question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Windows: no running event loop as of 22.3.0

See original GitHub issue

Describe the bug Hey, heads up, after updating to 22.3.0 a sanic server no longer starts on my Windows machine. Instead raises a RuntimeError: no running event loop. Seen this on two separate Windows machines so far.

Code snippet

# main.py
import sanic

app = sanic.Sanic("foo")

@app.get("/bar")
async def _(request):
    return sanic.response.text("buzz")

app.run(host="127.0.0.1", port=1337, access_log=False)
$ pipenv run python main.py
[2022-04-04 13:33:34 +0100] [14080] [INFO] 
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚                        Sanic v22.3.0                        β”‚
  β”‚               Goin' Fast @ http://0.0.0.0:1337              β”‚
  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
  β”‚                       β”‚     mode: production, single worker β”‚
  β”‚     β–„β–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆ     β”‚   server: sanic                     β”‚
  β”‚    β–ˆβ–ˆ                 β”‚   python: 3.9.2                     β”‚
  β”‚     β–€β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–„     β”‚ platform: Windows-10-10.0.22000-SP0 β”‚
  β”‚                 β–ˆβ–ˆ    β”‚ packages: sanic-routing==22.3.0     β”‚
  β”‚    β–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–€     β”‚                                     β”‚
  β”‚                       β”‚                                     β”‚
  β”‚ Build Fast. Run Fast. β”‚                                     β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

[2022-04-04 13:33:34 +0100] [14080] [WARNING] Sanic is running in PRODUCTION mode. Consider using '--debug' or '--dev' while actively developing your application.
[2022-04-04 13:33:34 +0100] [14080] [ERROR] Experienced exception while trying to serve
Traceback (most recent call last):
  File "C:\Users\James\.virtualenvs\test-lP8LJtvX\lib\site-packages\sanic\mixins\runner.py", line 578, in serve
    serve_single(primary_server_info.settings)
  File "C:\Users\James\.virtualenvs\test-lP8LJtvX\lib\site-packages\sanic\server\runners.py", line 206, in serve_single
    serve(**server_settings)
  File "C:\Users\James\.virtualenvs\test-lP8LJtvX\lib\site-packages\sanic\server\runners.py", line 146, in serve
    ctrlc_workaround_for_windows(app)
  File "C:\Users\James\.virtualenvs\test-lP8LJtvX\lib\site-packages\sanic\compat.py", line 91, in ctrlc_workaround_for_windows
    app.add_task(stay_active)
  File "C:\Users\James\.virtualenvs\test-lP8LJtvX\lib\site-packages\sanic\app.py", line 1217, in add_task
    loop = self.loop  # Will raise SanicError if loop is not started
  File "C:\Users\James\.virtualenvs\test-lP8LJtvX\lib\site-packages\sanic\app.py", line 255, in loop
    return get_running_loop()
RuntimeError: no running event loop
Traceback (most recent call last):
  File "C:\Users\James\Desktop\test\main.py", line 9, in <module>
    app.run(host='0.0.0.0', port=1337, access_log=False)
  File "C:\Users\James\.virtualenvs\test-lP8LJtvX\lib\site-packages\sanic\mixins\runner.py", line 145, in run
    self.class.serve(primary=self)  # type: ignore
  File "C:\Users\James\.virtualenvs\test-lP8LJtvX\lib\site-packages\sanic\mixins\runner.py", line 578, in serve
[2022-04-04 13:40:57 +0100] [22748] [WARNING] Sanic is running in PRODUCTION mode. Consider using '--debug' or '--dev' while actively developing your application.
[2022-04-04 13:40:57 +0100] [22748] [ERROR] Experienced exception while trying to serve
Traceback (most recent call last):
  File "C:\Users\James\.virtualenvs\test-lP8LJtvX\lib\site-packages\sanic\mixins\runner.py", line 578, in serve
    serve_single(primary_server_info.settings)
  File "C:\Users\James\.virtualenvs\test-lP8LJtvX\lib\site-packages\sanic\server\runners.py", line 206, in serve_single
    serve(**server_settings)
  File "C:\Users\James\.virtualenvs\test-lP8LJtvX\lib\site-packages\sanic\server\runners.py", line 146, in serve
    ctrlc_workaround_for_windows(app)
  File "C:\Users\James\.virtualenvs\test-lP8LJtvX\lib\site-packages\sanic\compat.py", line 91, in ctrlc_workaround_for_windows
    app.add_task(stay_active)
  File "C:\Users\James\.virtualenvs\test-lP8LJtvX\lib\site-packages\sanic\app.py", line 1217, in add_task
    loop = self.loop  # Will raise SanicError if loop is not started
  File "C:\Users\James\.virtualenvs\test-lP8LJtvX\lib\site-packages\sanic\app.py", line 255, in loop
    return get_running_loop()
RuntimeError: no running event loop
Traceback (most recent call last):
  File "C:\Users\James\Desktop\test\main.py", line 9, in <module>
    app.run(port=1337, access_log=False)
  File "C:\Users\James\.virtualenvs\test-lP8LJtvX\lib\site-packages\sanic\mixins\runner.py", line 145, in run
    self.class.serve(primary=self)  # type: ignore
  File "C:\Users\James\.virtualenvs\test-lP8LJtvX\lib\site-packages\sanic\mixins\runner.py", line 578, in serve
    serve_single(primary_server_info.settings)
  File "C:\Users\James\.virtualenvs\test-lP8LJtvX\lib\site-packages\sanic\server\runners.py", line 206, in serve_single
    serve(**server_settings)
  File "C:\Users\James\.virtualenvs\test-lP8LJtvX\lib\site-packages\sanic\server\runners.py", line 146, in serve
    ctrlc_workaround_for_windows(app)
  File "C:\Users\James\.virtualenvs\test-lP8LJtvX\lib\site-packages\sanic\compat.py", line 91, in ctrlc_workaround_for_windows
    app.add_task(stay_active)
  File "C:\Users\James\.virtualenvs\test-lP8LJtvX\lib\site-packages\sanic\app.py", line 1217, in add_task
    loop = self.loop  # Will raise SanicError if loop is not started
  File "C:\Users\James\.virtualenvs\test-lP8LJtvX\lib\site-packages\sanic\app.py", line 255, in loop
    return get_running_loop()
RuntimeError: no running event loop

Environment (please complete the following information):

  • OS: Windows 11 Pro
  • Version 10.0.22000 build 22000
  • Python: 3.9.2

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ahopkinscommented, Apr 19, 2022

It is this issue: https://github.com/sanic-org/sanic-ext/issues/70

Patch coming later today

1reaction
ahopkinscommented, Apr 17, 2022

v22.3.1 should resolve this and has been released. Feedback πŸ‘ or πŸ‘Ž would be appreciated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"RuntimeError: no running event loop" with "asyncio ...
If there is no running event loop a RuntimeError is raised. This function can only be called from a coroutine or a callback....
Read more >
Changelog β€” Sanic 22.9.1 documentation
This allows blueprints to be pickled and unpickled, without errors, which is a requirement of running Sanic in multiprocessing mode in Windows. Added...
Read more >
22.3.0 no running event loop - Sanic Community Discussion
I got a error when upgrate sanic to 22.3.0.
Read more >
Event Loop β€” Python 3.11.1 documentation
The loop must not be running when this function is called. Any pending callbacks will be discarded. This method clears all queues and...
Read more >
22.3.0 - GraalVM
Released the LLVM runtime for GraalVM Community Edition for Windows under experimental support. Updated the OpenJDK release on which GraalVMΒ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found