【发布时间】:2021-04-01 16:08:46
【问题描述】:
我想让两个非阻塞进程同步运行,一个是while True循环,每分钟缓存一次数据,第二个是如下代码:
def create_and_start_app():
app = Application([
('/dashboard', Dashboard)
],
debug=RuntimeConfig.DEBUG_MODE)
http_server = HTTPServer(app)
http_server.listen(RuntimeConfig.APP_PORT)
print(f'Listening on http:/{RuntimeConfig.APP_HOST}:{RuntimeConfig.APP_PORT}')
IOLoop.current().start()
我尝试了IOLoop.current.spawn_call_back 方法和concurrent.futures.ThreadPoolExecutor,但似乎我没有得到文档的重点,因为我测试的每种方法,在缓存方法和程序中都使用 while True 阻塞,不会执行下一个进程。谢谢你给我一个适合这种情况的示例代码。
【问题讨论】:
-
如何暂停
while循环?你在用time.sleep吗? -
是的,我使用 time.sleep
标签: python-3.x python-asyncio tornado