-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ASGI_THREADS environment variable has no effect since 2.4.1 #319
Comments
Nothing related to that was changed in 2.4.1, that stuff is all managed by asgiref. The thread stuff is a lot better in python 3.8 but imo the whole ThreadPoolExecutor design is terrible. |
I tested it, sorry, you're right. I assumed the correct loop was installed as global correctly. It seems like the "correct" ThreadPoolExecutor is installed on the wrong loop. |
Hmmm. Yes. It's because |
I assumed that https://github.com/django/daphne/blob/2.4.1/daphne/server.py#L129 would make it all correct but maybe stuff is executed in the wrong order. |
I've been testing this a bit further, this actually breaks everything that uses asyncio and is initialized at the "wrong" time. The original loop seems to be stopped. Now I have this piece of boilerplate code at the top somewhere imported early to make sure everything else uses the correct loop.
|
See django/asgiref#185 (comment):
|
#299 is related. |
So I have been looking through asgiref, channels daphne etc… and I came to the following conclusion: Remove
Okay, now with What do you think? |
@carltongibson:
with that in mind it might (?) be possible to actually revert the changes. That said I would recommend against reverting because creating our own event loop and configuring it as needed sounds like the way to go… Nevertheless I'd be interested to know if you have an idea whether python fixed something or we fixed a few bugs in asgiref along the way… |
Hey @apollo13 — thanks for digging. Current status is I don't know. My plan (since late Summer) has been to sit down with Daphne and resolve this issue properly. Life has intervened but, it's my top item (having just got 4.0 compatibility going for django-compressor). So reality is more work (from me) on the Channels Trio in the new year now. However, if you're digging actively I am very happy to work with you on that.
Yes, it seemed like a good idea. The issue was that it turns out that you need to set the event loop in your thread if you're not using the default, and whilst that's possible it creates a bookkeeping overhead, that folks don't want to do. I began a conversation with @orf on the Forum about not using thread for the auto-reloader that was prompted by this issue. https://forum.djangoproject.com/t/feasibility-of-using-subprocess-for-auto-reloader/4970 — That's the way I'd like to go (but that's a lot of Yak...) |
Hi @carltongibson, while it is true that changes to the autoreloader might be possible; I still think that |
Certainly happy for Daphne to have that. There needs to be some hard upper limit somewhere, and the protocol server seems the right level for that. (I can't recall without looking if there are other uses of |
OK, so I finally had the combination of time/energy/health to look into this (and the related cluster of issues) again. The bottom-line is that I think dropping PY36, and
That's very preliminary. (I only had the session today to look at it) But maybe the pandemic induced don't look at it for two years has paid off. I'll keep working on this, but it feels like what was intractable now at least has a way of being untangled. |
OK, so step one is RFC to remove ASGI_THREADS from asgiref: django/asgiref#336 Then we'll bring similar in here to restore this functionality to Daphne. |
OK, initial port of the environment variable handling in #422. |
Hello @carltongibson, Thanks a lot |
@aeyoll no. You'd be welcome to backport it yourself and deploy that patched versions, or else update to the new version. (Beta on PyPI now. Final in a couple of weeks.) |
Thanks for the answer! Maybe it should be pertinent to add a note on the documentation, specifying the versions where it doesn't work. |
Channels documentation mentions that:
This behaviour used to work correctly before Daphne v2.4.1.
Since 2.4.1 setting ASGI_THREADS envvar has no effect.
My Setup
Python 3.7.5, on Ubuntu 19.10 with following packages:
Startup:
How to replicate
The text was updated successfully, but these errors were encountered: