flask和uwsgi下的线程化python应用程序。失败

时间:2018-07-27 14:53:26

标签: python ubuntu flask wsgi flask-restful

这是我第一次处理flask / uwsgi。 我遵循以下指南: https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uwsgi-and-nginx-on-ubuntu-16-04

*仅尝试在uwsgi下不进行烧瓶开发的情况下效果很好。

运行uwsgi服务器的命令:

uwsgi --socket 0.0.0.0:5007 --protocol=http -w wsgi:app --enable-threads

我的应用程序是多线程的,运行没有gui的chrome-selenium:

from flask import Flask, request
from flask_restful import Resource, Api
import queue
import threading
...
threadList = ['111', '222']
queueLock = threading.Lock()
workQueue = queue.Queue(10)
threads = []
threadID = 1

# Create new threads
for tName in threadList:
    thread = myThread(threadID, tName, workQueue)
    thread.start()
    threads.append(thread)
    threadID += 1
    sleep(5)
app = Flask(__name__)
api = Api(app)
api.add_resource(user_info, '/userinfo')  # Route_3

if __name__ == '__main__':
    app.run(host='0.0.0.0', port='5007')

# Notify threads it's time to exit
exitFlag = 1

# Wait for all threads to complete
for t in threads:
   t.join()
print ("Exiting Main Thread")

应用程序启动良好,但是线程无故停止。 uwsgi日志:

(pythonenv) imagereco@imagereco-virtual-machine:~/www/zzz/xxx/yyy$ uwsgi --socket 0.0.0.0:5007 --protocol=http -w wsgi:app --enable-threads
*** Starting uWSGI 2.0.17.1 (64bit) on [Fri Jul 27 17:49:17 2018] ***
compiled with version: 5.4.0 20160609 on 24 July 2018 19:06:06
os: Linux-4.15.0-29-generic #31~16.04.1-Ubuntu SMP Wed Jul 18 08:54:04 UTC 2018
nodename: imagereco-virtual-machine
machine: x86_64
clock source: unix
detected number of CPU cores: 2
current working directory: xxx...
detected binary path: xxx.../bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 7652
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to TCP address 0.0.0.0:5007 fd 3
Python version: 3.5.2 (default, Nov 23 2017, 16:37:01)  [GCC 5.4.0 20160609]
Python main interpreter initialized at 0x1fa7320
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72920 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
xxx/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
  return f(*args, **kwds)

0 个答案:

没有答案