Skip to content

WorkerManager.kill doesn't support Windows #3043

@m-legrand

Description

@m-legrand

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Once I run the app in debug mode and move to the /docs page, I get a fatal error coming from the WorkerManager.kill function trying to call os.killpg, a function unavailable on Windows.

$ sanic server:app --dev

Uninstalled 1 package in 4ms
Installed 1 package in 26ms
Module 'readline' not available. History navigation will be limited.
Main  11:17:07 INFO:
  ┌────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  │                                             Sanic v24.12.0                                             │
  │                                   Goin' Fast @ http://127.0.0.1:8000                                   │
  ├───────────────────────┬────────────────────────────────────────────────────────────────────────────────┤
  │                       │         app: server                                                            │
  │     ▄███ █████ ██     │        mode: debug, single worker                                              │
  │    ██                 │      server: sanic, HTTP/1.1                                                   │
  │     ▀███████ ███▄     │      python: 3.12.3                                                            │
  │                 ██    │    platform: Windows-10-10.0.19045-SP0                                         │
  │    ████ ████████▀     │ auto-reload: enabled                                                           │
  │                       │    packages: sanic-routing==23.12.0, sanic-testing==24.6.0, sanic-ext==24.12.0 │
  │ Build Fast. Run Fast. │                                                                                │
  └───────────────────────┴────────────────────────────────────────────────────────────────────────────────┘

Main  11:17:07 DEBUG:  Creating multiprocessing context using 'spawn'

Press ENTER at anytime to start the REPL.

Main  11:17:08 INFO:   Sanic Extensions:
Main  11:17:08 INFO:     > injection [0 dependencies; 0 constants]
Main  11:17:08 INFO:     > openapi [http://127.0.0.1:8000/docs]
Main  11:17:08 INFO:     > http
Main  11:17:08 INFO:     > templating [jinja2==3.1.5]
Main  11:17:08 DEBUG:  Starting a process: Sanic-Server-0-0
Main  11:17:08 DEBUG:  Starting a process: Sanic-Reloader-0
Main  11:17:40 ERROR:  Not all workers acknowledged a successful startup. Shutting down.

It seems that one or more of your workers failed to come online in the allowed time. Sanic is shutting down to avoid a deadlock. The current threshold is 30.0s. If this problem persists, please check out the documentation https://sanic.dev/en/guide/deployment/manager.html#worker-ack.
Main  11:17:40 INFO:   Killing Sanic-Server-0-0 [37416]
Main  11:17:40 ERROR:  Experienced exception while trying to serve
Traceback (most recent call last):
  File "C:\Dev\project\.venv\Lib\site-packages\sanic\mixins\startup.py", line 1141, in serve
    manager.run()
  File "C:\Dev\project\.venv\Lib\site-packages\sanic\worker\manager.py", line 194, in run
    self.monitor()
  File "C:\Dev\project\.venv\Lib\site-packages\sanic\worker\manager.py", line 291, in monitor
    self.wait_for_ack()
  File "C:\Dev\project\.venv\Lib\site-packages\sanic\worker\manager.py", line 338, in wait_for_ack
    self.kill()
  File "C:\Dev\project\.venv\Lib\site-packages\sanic\worker\manager.py", line 375, in kill
    os.killpg(os.getpgid(process.pid), SIGKILL)
    ^^^^^^^^^
AttributeError: module 'os' has no attribute 'killpg'. Did you mean: 'kill'?
Main  11:17:40 INFO:   Server Stopped
Main  11:17:51 WARN:   Worker shutdown timed out. Some processes may still be running.
Main  11:17:51 DEBUG:  Take care
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Dev\project\.venv\Scripts\sanic.exe\__main__.py", line 8, in <module>
  File "C:\Dev\project\.venv\Lib\site-packages\sanic\__main__.py", line 12, in main
    cli.run(args)
  File "C:\Dev\project\.venv\Lib\site-packages\sanic\cli\app.py", line 142, in run
    serve(app)
  File "C:\Dev\project\.venv\Lib\site-packages\sanic\mixins\startup.py", line 1141, in serve
    manager.run()
  File "C:\Dev\project\.venv\Lib\site-packages\sanic\worker\manager.py", line 194, in run
    self.monitor()
  File "C:\Dev\project\.venv\Lib\site-packages\sanic\worker\manager.py", line 291, in monitor
    self.wait_for_ack()
  File "C:\Dev\project\.venv\Lib\site-packages\sanic\worker\manager.py", line 338, in wait_for_ack
    self.kill()
  File "C:\Dev\project\.venv\Lib\site-packages\sanic\worker\manager.py", line 375, in kill
    os.killpg(os.getpgid(process.pid), SIGKILL)
    ^^^^^^^^^
AttributeError: module 'os' has no attribute 'killpg'. Did you mean: 'kill'?

Code snippet

from sanic import Sanic
from sanic.response import json

app = Sanic(__name__)


@app.route("/")
async def hello_world(request):
    return json({"hello": "world"})

Expected Behavior

The app running, including when visiting http://127.0.0.1:8000/docs

How do you run Sanic?

Sanic CLI

Operating System

Windows

Sanic Version

Sanic 24.12.0; Routing 23.12.0

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions