wowkin2 / django-test-streaming-response

Repo to show how Django StreamingHttpResponse works with async views
5 stars 0 forks source link

RuntimeError: cannot schedule new futures after interpreter shutdown #3

Open bblanchon opened 3 years ago

bblanchon commented 3 years ago

Hi,

If you run a second instance of test_stream.py, you get the following error:

(redacted)\lib\site-packages\django\template\base.py:766: RuntimeWarning: coroutine 'AsyncToSync.main_wrap' was never awaited
  self.literal = float(var)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Internal Server Error: /sse_async
Traceback (most recent call last):
  File "(redacted)\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "(redacted)\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "(redacted)\lib\site-packages\asgiref\sync.py", line 114, in __call__
    self._run_event_loop, loop, awaitable
  File "(redacted)\python37\lib\concurrent\futures\thread.py", line 165, in submit
    raise RuntimeError('cannot schedule new futures after '
RuntimeError: cannot schedule new futures after interpreter shutdown
2020-08-21 09:48:56,674 django.request  ERROR   Internal Server Error: /sse_async
Traceback (most recent call last):
  File "(redacted)\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "(redacted)\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "(redacted)\lib\site-packages\asgiref\sync.py", line 114, in __call__
    self._run_event_loop, loop, awaitable
  File "(redacted)\python37\lib\concurrent\futures\thread.py", line 165, in submit
    raise RuntimeError('cannot schedule new futures after '
RuntimeError: cannot schedule new futures after interpreter shutdown

Tested with:

Best regards, Benoit

wowkin2 commented 3 years ago

Run 2 instances at the same time - see log files added in this commit.

This can probably be because of you pressed Ctrl+C to shutdown server-side and system just hasn't finished it. After you run it again - should work.

bblanchon commented 3 years ago

Hi @wowkin2,

Thank you for your prompt response.

You're right; I did press Ctrl+C. I retried with a fresh instance and didn't get this exception.

However, I still see nothing in the client, so I cannot verify that it works. Also, the server show "Generated message for iteration" only for the first client, so I'm assuming that it's not catching the other connections.

In your message, you say "Run 2 instances", do you mean "run two instances of the server"? Unfortunately, it's not an option for me: I cannot have one process per client. Moreover, it defeats the purpose of async views.

Best regards, Benoit

wowkin2 commented 3 years ago

@bblanchon no, I run 2 simultaneous instances of test_stream.py and 1 web-server (daphne).