Open fcurella opened 4 years ago
I was having the same problem, eventually I solved it by using the app.loop
, so you use the same loop as the app:
async def article_changed(article_id, is_new):
future = await topic.send(value=ChangeRecord(id=article_id, is_new=is_new))
return await future # For some reason it does not work without awaiting twice
So from a model save you can trigger this async this way:
def save(self, *args, **kwargs):
...
loop = app.loop
coroutine = article_changed(article_id=self.id, is_new=is_new)
loop.run_until_complete(coroutine)
Checklist
master
branch of Faust.Steps to reproduce
I'd like to use the Django ORM to save some data into Postgres. Django recommends using asgiref's
sync_to_async
, but that relies on usingasync_to_sync
above in the stack:I've tried wrapping
worker.start()
inasync_to_sync()
, but it looks like Faust is trying to register signal handlers on the wrong Thread, ie: the thread created byasync_to_sync
, rather than the main thread.Expected behavior
Worker starts successfully.
Actual behavior
Starting up the worker fails with
ValueError: set_wakeup_fd only works in main thread
.Full traceback
Versions