Channels 2 using asyncio run_in_executor

classic Classic list List threaded Threaded
3 messages Options
B-2
Reply | Threaded
Open this post in threaded view
|

Channels 2 using asyncio run_in_executor

B-2
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3be88116-f199-483e-9ee9-73d3a292c81d%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Channels 2 using asyncio run_in_executor

Andrew Godwin-3
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 <[hidden email]> 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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3be88116-f199-483e-9ee9-73d3a292c81d%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFwN1uo%2BC9wS-%2BjEpz9OaUXcS7hO2SauxA9evUUuTiraOS69ww%40mail.gmail.com.
B-2
Reply | Threaded
Open this post in threaded view
|

Re: Channels 2 using asyncio run_in_executor

B-2
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 <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="NPbQRswgAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rac...@...> 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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="NPbQRswgAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/3be88116-f199-483e-9ee9-73d3a292c81d%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/3be88116-f199-483e-9ee9-73d3a292c81d%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/3be88116-f199-483e-9ee9-73d3a292c81d%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/3be88116-f199-483e-9ee9-73d3a292c81d%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7d4ce7dc-2000-41e6-9de8-280769c92ddb%40googlegroups.com.