Skip to content
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

Cannot stop Daphne process #2

Open
bblanchon opened this issue Aug 21, 2020 · 5 comments
Open

Cannot stop Daphne process #2

bblanchon opened this issue Aug 21, 2020 · 5 comments

Comments

@bblanchon
Copy link

Hi,

As soon as someone gets /sse_async, the Daphne process enters an infinite loop and cannot be stopped with Ctrl-C.

Tested with:

  • Windows 10
  • Python 3.7.7
  • Django 3.1
  • Daphne 2.5.0
  • nest-asyncio 1.4.0
  • requests 2.24.0

Best regards,
Benoit

@wowkin2
Copy link
Owner

wowkin2 commented Aug 21, 2020

It is not an infinite loop.
Django creates separate thread that generates response.
On Ctrl+C it shutdowns main thread, but process is waiting for other threads.
If you really need to stop it - press Ctrl+C one more time and it will stop it.

@bblanchon
Copy link
Author

Hi @wowkin2,

Thanks for this answer.

I pressed Ctrl-C a dozen times, but the server won't stop.
Yesterday I saw the same problem on Docker on macOS, so I don't think it's related to Windows.

Django creates separate thread that generates response.

I'm really puzzled by this sentence.
The whole point of async views is to reduce the number of threads, right?
Or, as I put it in the [SO question]:

implement an SSE view without monopolizing a thread per client

Best regards,
Benoit

@wowkin2
Copy link
Owner

wowkin2 commented Aug 21, 2020

@bblanchon then you need to understand if you want to utilize async or fix StreamHttpResponse.
If first - then you need another solution.

Describe what is the purpose of SSE in your case or what you want to achive? Because goal to

implement an SSE view without monopolizing a thread per client
looks like you want to push something from time to time to Frontend, and not reply with big file (main purpose of StreamingHttpResponse)

@bblanchon
Copy link
Author

I'm sorry @wowkin2, I didn't realize there could be any ambiguity here.
SSE is for sending events from the server to the client; I never said I wanted to send large responses.

As I mentioned in the question, I used StreamingHttpResponse because it was successfully used for SSE in this other SO question, the only problem is that it uses a synchronous view.

@wowkin2
Copy link
Owner

wowkin2 commented Aug 25, 2020

@bblanchon "send large responses" is one of purposes of StreamingHttpResponse.
And as I don't know how you are using it right now, I can't suggest the best async solution for you. Perhaps Django Channels is completely enough for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants