TornadoScheduler在tornado启动的flask中报错该如何解决

from flask import Flask
app=Flask(__name__)

#from apscheduler.schedulers.tornado import TornadoScheduler
#scheduler=TornadoScheduler()
#scheduler.start()

@app.route('/')
def index():
    return 'Flask'

from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from tornado.options import options,define
from tornado.wsgi import WSGIContainer

try:
    ####转换变量为对应属性
    options.parse_command_line()
    http_server = HTTPServer(WSGIContainer(app))
    http_server.bind(port=8000)
    http_server.start(1)
    IOLoop.instance().start()
except KeyboardInterrupt:
    pass

一旦把http_server.start(num_processes)设为大于1的进程数,并且把TornadoScheduler放开,就开始报错,报错如下,各位大神帮忙看看怎么写才能在多进程下使用TornadoScheduler

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/selector_events.py", line 262, in _add_reader
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/selector_events.py", line 262, in _add_reader
    key = self._selector.get_key(fd)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/selectors.py", line 192, in get_key
    key = self._selector.get_key(fd)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/selectors.py", line 192, in get_key
    raise KeyError("{!r} is not registered".format(fileobj)) from None    
raise KeyError("{!r} is not registered".format(fileobj)) from None
KeyErrorKeyError: : '7 is not registered''7 is not registered'


During handling of the above exception, another exception occurred:


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
Traceback (most recent call last):
  File "/Users/Jeason/Documents/PycharmProjects/monitor/app.py", line 27, in <module>
  File "/Users/Jeason/Documents/PycharmProjects/monitor/app.py", line 27, in <module>
        http_server.start(options.processes)
http_server.start(options.processes)  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tornado/tcpserver.py", line 222, in start

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tornado/tcpserver.py", line 222, in start
    self.add_sockets(sockets)    
self.add_sockets(sockets)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tornado/tcpserver.py", line 158, in add_sockets
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tornado/tcpserver.py", line 158, in add_sockets
    sock, self._handle_connection)    
sock, self._handle_connection)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tornado/netutil.py", line 268, in add_accept_handler
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tornado/netutil.py", line 268, in add_accept_handler
    io_loop.add_handler(sock, accept_handler, IOLoop.READ)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tornado/platform/asyncio.py", line 80, in add_handler
    io_loop.add_handler(sock, accept_handler, IOLoop.READ)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tornado/platform/asyncio.py", line 80, in add_handler
    fd, self._handle_events, fd, IOLoop.READ)
    fd, self._handle_events, fd, IOLoop.READ)  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/selector_events.py", line 335, in add_reader

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/selector_events.py", line 335, in add_reader
    return self._add_reader(fd, callback, *args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/selector_events.py", line 265, in _add_reader
    return self._add_reader(fd, callback, *args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/selector_events.py", line 265, in _add_reader
    (handle, None))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/selectors.py", line 522, in register
    (handle, None))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/selectors.py", line 522, in register
    self._selector.control([kev], 0, 0)
OSError:     self._selector.control([kev], 0, 0)[Errno 9] Bad file descriptor

OSError: [Errno 9] Bad file descriptor
[W 190128 12:41:12 process:163] child 1 (pid 7060) exited with status 1, restarting
[W 190128 12:41:12 process:163] child 0 (pid 7059) exited with status 1, restarting
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/selector_events.py", line 262, in _add_reader
    key = self._selector.get_key(fd)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/selectors.py", line 192, in get_key
    raise KeyError("{!r} is not registered".format(fileobj)) from None
KeyError: '7 is not registered'
阅读 3.5k
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题