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.

Need to KeyboardInterrupt 3 times to stop the server

See original GitHub issue

โ“ Iโ€™m submitting a โ€ฆ

  • ๐Ÿž bug report
  • ๐Ÿฃ feature request
  • โ“ question about the decisions made in the repository

๐Ÿž Describe the bug. What is the current behavior? I am trying out cheroot for the first time today. When I run my flask application with cheroot, I find that to stop the application, I need to hit Ctrl+C 3 times - even if I wait for nearly 2-3 minutes and no requests are being processed.

โ“ What is the motivation / use case for changing the behavior? It intuitively stop if I hit the Ctrl+C once I think ?

๐Ÿ’ก To Reproduce

$ mkdir -p /tmp/cheroottesting
$ cd /tmp/cheroottesting
$ python -m venv venv
$ venv/bin/pip install cheroot
$ cat app.py
from wsgiref.simple_server import make_server

def application(environ, start_response):
    status = '200 OK'
    response_headers = [('Content-type', 'text/plain')]
    start_response(status, response_headers)
    return [b"Hello World !"]
$ export PYTHONPATH=.
$ venv/bin/cheroot app:application -b 0.0.0.0:5000

What I observe: untitled

Note: I have tried to wait for about 30sec after hitting Ctrl-C for it to complete cleaning up after itself, didnt help much

๐Ÿ’ก Expected behavior The server should have stopped after I hit the first Ctrl-C

๐Ÿ“‹ Details

$ venv/bin/cheroot app:application --bind 0.0.0.0:5000

^CKeyboard Interrupt: shutting down


^CTraceback (most recent call last):
  File "/tmp/cheroottesting/venv/lib/python3.7/site-packages/cheroot/server.py", line 1710, in safe_start
    self.start()
  File "/tmp/cheroottesting/venv/lib/python3.7/site-packages/cheroot/server.py", line 1819, in start
    self.serve()
  File "/tmp/cheroottesting/venv/lib/python3.7/site-packages/cheroot/server.py", line 1798, in serve
    self.tick()
  File "/tmp/cheroottesting/venv/lib/python3.7/site-packages/cheroot/server.py", line 2038, in tick
    conn = self._connections.get_conn()
  File "/tmp/cheroottesting/venv/lib/python3.7/site-packages/cheroot/connections.py", line 137, in get_conn
    in self._selector.select(timeout=0.01)
  File "/home/abdealijk/miniconda3/lib/python3.7/selectors.py", line 468, in select
    fd_event_list = self._selector.poll(timeout, max_ev)
KeyboardInterrupt

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "venv/bin/cheroot", line 10, in <module>
    sys.exit(main())
  File "/tmp/cheroottesting/venv/lib/python3.7/site-packages/cheroot/cli.py", line 241, in main
    raw_args._wsgi_app.server(raw_args).safe_start()
  File "/tmp/cheroottesting/venv/lib/python3.7/site-packages/cheroot/server.py", line 1715, in safe_start
    self.stop()
  File "/tmp/cheroottesting/venv/lib/python3.7/site-packages/cheroot/server.py", line 2071, in stop
    time.sleep(0.1)
KeyboardInterrupt


^CException ignored in: <module 'threading' from '/home/abdealijk/miniconda3/lib/python3.7/threading.py'>
Traceback (most recent call last):
  File "/home/abdealijk/miniconda3/lib/python3.7/threading.py", line 1307, in _shutdown
    lock.acquire()
KeyboardInterrupt

๐Ÿ“‹ Environment

  • Cheroot version: 8.4.5
  • CherryPy version: Not using it
  • Python version: 3.7.7
  • OS: Windows 10 + Ubuntu 18.04.4 LTS in WSL2
  • Browser: Not applicable

๐Ÿ“‹ Additional context Maybe this is related to: https://github.com/cherrypy/cheroot/issues/323

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
The-Compilercommented, Nov 10, 2020

FWIW this also seems to affect SIGTERM, which causes the server to not exit at all (even when doing it multiple times).

0reactions
webknjazcommented, Nov 10, 2020

@loqs Iโ€™m pretty sure the CherryPy test is flaky regardless. Thatโ€™s why itโ€™s important to have a good test here too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to stop a script totally with Keyboard Interrupt
You need to catch the Ctrl+C in Python so that you can correctly terminate the program and safely exit by the use of...
Read more >
Complete Guide to Python KeyboardInterrupt
Guide to Python KeyboardInterrupt. Here we discuss how KeyboardInterrupt exception work, how to avoid KeyboardInterrupt exceptions in Python.
Read more >
Control-C handling in Python and Trio โ€” njs blog
By default, the Python interpreter sets things up so that control-C will cause a KeyboardInterrupt exception to materialize at some point inย ...
Read more >
python keyboard interrupt - You.com | The AI Search ...
Keyboard Interrupt. One of the most common methods to stop a script is by using the following keyboard shortcut, which is known as...
Read more >
Why does Ctrl + C not kill Python running in terminal?
CTRL+C historically has stopped only the current job-in-process, and not brought down the entire stack that job depends upon. Or it Copiesย ...
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