In a project I'm working in I need to cover a Tornado service with Behave so I want to start an instance of my tornado service before running each scenario.
Naively trying to run the loop as part before all seems to lock the excecution:
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()
So it's probably not what I need.
Your IOLoop is running in the main thread, so it's blocking. You could do it in a separate thread or process.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With