小编J A*_*ish的帖子

Workers 中的 Python uwsgi 线程

uwsgi 新手,当我运行以下代码时

\n\n
from time import sleep\nimport threading\nimport os\nimport sys\n\n\ni = 0\n\n\ndef daemon():\n    print("pid ", os.getpid())\n    global i\n    while True:\n        i += 1\n        print("pid ", os.getpid(), i)\n        sleep(3)\n\n\nth = threading.Thread(target=daemon, args=())\nth.start()\n\nprint("application pid ", os.getpid())\n\n\ndef application(environ, start_response):\n    start_response(\'200 OK\', [(\'Content-Type\', \'text/html\')])\n    return [str(i).encode()]\n\n\ndef atexit(*args):\n    import uwsgi\n    print(\'At exit called \', uwsgi.worker_id(), os.getpid())\n    sys.exit(1)\n\n\ntry:\n    import uwsgi\n    uwsgi.atexit = atexit\nexcept ImportError:\n    pass\n
Run Code Online (Sandbox Code Playgroud)\n\n

使用命令

\n\n
uwsgi --http :9090 --wsgi-file  wsgi.py  --enable-threads --processes 2\n
Run Code Online (Sandbox Code Playgroud)\n\n

我得到输出

\n\n
*** WARNING: you are running uWSGI without …
Run Code Online (Sandbox Code Playgroud)

python multithreading uwsgi

5
推荐指数
1
解决办法
6692
查看次数

标签 统计

multithreading ×1

python ×1

uwsgi ×1