如何在gunicorn中启用线程

时间:2016-12-08 13:50:37

标签: python multithreading gunicorn

这是我的工作人员脚本代码worker.py

def app():
   # do some stuff
   threads = [] 
   t = threading.Thread(target = some_method, args = (1,2))
   threads += [t]
        t.start()

    for t in threads:
        t.join()

如果我像这样运行它:

 phython worker.py

它有效。但如果我像这样运行它:      gunicorn -c gunicorn_config.py worker:app

它被困在线程部分。线程正在下载图像,所以我宁愿并行处理。

我的配置是这样的:

worker_class = 'sync'
worker_connections = 1000
timeout = 360
keepalive = 2
#This is  the nuclear option. will print everything to log
spew = False
daemon = False
pidfile = 'master.pid'
umask = 0
user = None
group = None
tmp_upload_dir = None
logfile = 'log_tmp.log'
errorlog = '-'
loglevel = 'info'
accesslog = '-'
proc_name = 'GenericGunicorn'
# 0 is unlimited
limit_request_line = 0

我的问题是:

  1. 我该如何解决?让线程工作?
  2. 如果我不能,我为什么要在一台机器上运行多个工作进程?

0 个答案:

没有答案