Closed hassanselim0 closed 5 months ago
I hope this makes its way to a hotfix release soon-ish because currently I have this ugly workaround code that runs for every gunicorn thread:
try:
asyncio.get_event_loop()
except RuntimeError as e:
if str(e).startswith('There is no current event loop in thread'):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
else:
raise
I'm basically creating an event loop for each thread even though I don't need one, just so things don't break when I try to construct a faust app object.
On further review, I agree that lazy loading is the right thing to do. I need to see if there's a regression test that covers the issue I originally attempted to patch in https://github.com/faust-streaming/mode/issues/38.
I'll push a release out tomorrow. I try to stay out of the habit of releasing changes on weekends.
The
_new_*_event
methods on theService
class were calling theloop
property instead of using the_loop
attribute, the property tried to fetch the current thread's event loop which caused some odd issues, this fix delays that until the event loop is actually needed (lazy loading).This fixes #61