Skip to content

Cannot use Ctrl + C to exit the program normally #2986

@lky1937

Description

@lky1937

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Use Ctrl + C to interrupt the program when the program startup is not complete, and subsequent Ctrl + C will fail.

The operation procedure and related logs are as follows:

  1. Use Ctrl + C for the first time
    [2024-07-16 13:04:06 +0800] [19752] [INFO] Received signal SIGINT. Shutting down.
    Traceback (most recent call last):
    File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
    File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
    File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/sanic/worker/serve.py", line 117, in worker_serve
    return _serve_http_1(
    File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/sanic/server/runners.py", line 257, in _serve_http_1
    loop.run_until_complete(app._server_event("init", "before"))
    File "uvloop/loop.pyx", line 1511, in uvloop.loop.Loop.run_until_complete
    File "uvloop/loop.pyx", line 1504, in uvloop.loop.Loop.run_until_complete
    File "uvloop/loop.pyx", line 1377, in uvloop.loop.Loop.run_forever
    File "uvloop/loop.pyx", line 555, in uvloop.loop.Loop._run
    File "uvloop/handles/poll.pyx", line 216, in uvloop.loop.__on_uvpoll_event
    File "uvloop/cbhandles.pyx", line 83, in uvloop.loop.Handle._run
    File "uvloop/cbhandles.pyx", line 66, in uvloop.loop.Handle._run
    File "uvloop/loop.pyx", line 397, in uvloop.loop.Loop._read_from_self
    File "uvloop/loop.pyx", line 402, in uvloop.loop.Loop._invoke_signals
    File "uvloop/loop.pyx", line 377, in uvloop.loop.Loop._ceval_process_signals
    KeyboardInterrupt

  2. Use Ctrl + C for the second or more time
    [2024-07-16 13:04:08 +0800] [19752] [INFO] Shutdown interrupted. Killing.
    [2024-07-16 13:04:08 +0800] [19752] [INFO] Killing Sanic-Server-0-0 [19757]
    [2024-07-16 13:04:08 +0800] [19752] [INFO] Received signal SIGINT. Shutting down.

Code snippet

import asyncio

from sanic.app import Sanic

app = Sanic(name='test_sanic')


@app.listener('before_server_start')
async def before_server_start(app, loop):
    await asyncio.sleep(5)

Expected Behavior

No response

How do you run Sanic?

Sanic CLI

Operating System

MacOS

Sanic Version

23.12.2

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions