Channels 2 using asyncio run_in_executor

46 views
Skip to first unread message

BR

unread,
Oct 18, 2019, 2:26:12 PM10/18/19
to Django users
Should I expect any issues using asyncio run_in_executor to run blocking code? I realize there is the sync_to_async function as well, but that wasn't working in my case. I'm using multiprocessing.Queue to share data with a new process, and when I try to use queue.get() with either sync_to_async or run_in_executor, the calling method hangs.

My solution for now was to run a queue.get() listener in a separate thread, but it would have been nicer to use await with run_in_executor. Is there any custom configuration of the consumer event loop that prevents some times of functions from running, even when run with appropriate wrapping functions?

Andrew Godwin

unread,
Oct 18, 2019, 2:37:25 PM10/18/19
to django...@googlegroups.com
It should be fine, but you will need to be careful - there's a lot of side-effects with run_in_executor you should be aware of like the way exceptions propagate (Django won't handle them right for you) and the possibility of deadlock.

Andrew

On Fri, Oct 18, 2019 at 11:27 AM BR <rac...@gmail.com> wrote:
Should I expect any issues using asyncio run_in_executor to run blocking code? I realize there is the sync_to_async function as well, but that wasn't working in my case. I'm using multiprocessing.Queue to share data with a new process, and when I try to use queue.get() with either sync_to_async or run_in_executor, the calling method hangs.

My solution for now was to run a queue.get() listener in a separate thread, but it would have been nicer to use await with run_in_executor. Is there any custom configuration of the consumer event loop that prevents some times of functions from running, even when run with appropriate wrapping functions?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3be88116-f199-483e-9ee9-73d3a292c81d%40googlegroups.com.

BR

unread,
Oct 18, 2019, 4:59:47 PM10/18/19
to Django users
From your experience, can you provide a brief overview of the types of calls that would cause a deadlock?

Maybe that's what I was experiencing earlier, but after spending today on a work around, I can't replicate my original problem. Both sync_to_async and run_in_executor work just fine right now.


On Friday, October 18, 2019 at 2:37:25 PM UTC-4, Andrew Godwin wrote:
It should be fine, but you will need to be careful - there's a lot of side-effects with run_in_executor you should be aware of like the way exceptions propagate (Django won't handle them right for you) and the possibility of deadlock.

Andrew

On Fri, Oct 18, 2019 at 11:27 AM BR <rac...@gmail.com> wrote:
Should I expect any issues using asyncio run_in_executor to run blocking code? I realize there is the sync_to_async function as well, but that wasn't working in my case. I'm using multiprocessing.Queue to share data with a new process, and when I try to use queue.get() with either sync_to_async or run_in_executor, the calling method hangs.

My solution for now was to run a queue.get() listener in a separate thread, but it would have been nicer to use await with run_in_executor. Is there any custom configuration of the consumer event loop that prevents some times of functions from running, even when run with appropriate wrapping functions?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages