Skip to content

Instantly share code, notes, and snippets.

@masayuki038
Created October 5, 2019 03:28
Show Gist options
  • Save masayuki038/f9f9396d32320adc0af8cb882bc26ad2 to your computer and use it in GitHub Desktop.
Save masayuki038/f9f9396d32320adc0af8cb882bc26ad2 to your computer and use it in GitHub Desktop.
Getting thread dump of each process (master / workers) of uWSGI
from time import sleep
import os
import json
import threading
from flask import Flask, jsonify
from uwsgidecorators import postfork
import pystuck
pystuck.run_server(unix_socket='/tmp/utd-master')
i = 0
app = Flask(__name__)
@postfork
def worker_init():
pystuck.run_server(unix_socket=f'/tmp/utd-{os.getpid()}')
def process():
while True:
try:
global i
i += 1
print(f"i: {i}")
except Exception as err:
print(f"err: {err}")
sleep(5)
th = threading.Thread(target=process, name='test-thread', daemon=False)
th.start()
@app.route('/hello')
def hello_world():
sleep(5)
return jsonify({'message': f'Hello World, {i}, {threading.currentThread().ident}'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment