from flask import Flask
app=Flask(__name__)
-sharpfrom apscheduler.schedulers.tornado import TornadoScheduler
-sharpscheduler=TornadoScheduler()
-sharpscheduler.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:
-sharp-sharp-sharp-sharp
options.parse_command_line()
http_server = HTTPServer(WSGIContainer(app))
http_server.bind(port=8000)
http_server.start(1)
IOLoop.instance().start()
except KeyboardInterrupt:
pass
once you set http_server.start (num_processes) to the number of processes greater than 1 and release TornadoScheduler, you will start to report an error as follows. Please take a look at how to write to use TornadoScheduler in multiple processes
.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"