python – 如何在行为环境设置期间运行Tornado IO Loop
发布时间:2020-05-23 19:58:29 所属栏目:Python 来源:互联网
导读:在我正在工作的项目中,我需要用 Behave覆盖 Tornado服务,所以我想在运行每个场景之前启动龙卷风服务的实例. 天真地尝试将循环作为一部分运行之前似乎锁定了执行: from tornado import ioloopfrom tornadoadapter.applications import APPLICATIONdef before_
|
在我正在工作的项目中,我需要用 Behave覆盖 Tornado服务,所以我想在运行每个场景之前启动龙卷风服务的实例. 天真地尝试将循环作为一部分运行之前似乎锁定了执行: from tornado import ioloop
from tornadoadapter.applications import APPLICATION
def before_all(context):
print "Service running on port 8000"
APPLICATION.listen(8000)
ioloop.IOLoop.instance().start()
所以它可能不是我需要的. 解决方法您的IOLoop正在主线程中运行,因此它正在阻塞.您可以在单独的线程或进程中执行此操作.from multiprocessing import Process
from tornado import ioloop
from tornadoadapter.applications import APPLICATION
def run_server():
print "Service running on port 8000"
APPLICATION.listen(8000)
ioloop.IOLoop.instance().start()
def before_all(context):
context.server_thread = Process(target=run_server)
context.server_thread.deamon = True
context.server_thread.start() (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
