Skip to content

Commit

Permalink
Merge remote-tracking branch 'liamstask/ctrlc-fix'
Browse files Browse the repository at this point in the history
This change addresses a regression that manifested itself as a server
that didn't stop on the first SIGINT it got.

Ref #350
  • Loading branch information
webknjaz committed Dec 12, 2020
2 parents 4687852 + f3624d3 commit 3e73dd6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
:py:meth:`HTTPServer.interrupt <cheroot.server.\
HTTPServer.interrupt>` property -- by :user:`liamstask`.

- :pr:`350`: Fixed the incarnation of an earlier regression
of not resetting the serving state
on :py:data:``SIGINT`` originally fixed by :pr:`322` and
:pr:`331` but reintroduced by the changes in :pr:`311`
-- by :user:`liamstask`.

.. scm-version-title:: v8.5.0

- :issue:`305` via :pr:`311`: In
Expand Down
8 changes: 6 additions & 2 deletions cheroot/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ def run(self, expiration_interval):
Can be shut down by calling `stop()`.
"""
self._serving = True
try:
self._run(expiration_interval)
finally:
self._serving = False

def _run(self, expiration_interval):
last_expiration_check = time.time()

while not self._stop_requested:
Expand All @@ -222,8 +228,6 @@ def run(self, expiration_interval):
self._expire()
last_expiration_check = now

self._serving = False

def _remove_invalid_sockets(self):
"""Clean up the resources of any broken connections.
Expand Down
4 changes: 2 additions & 2 deletions cheroot/test/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ def test_serving_is_false_and_stop_returns_after_ctrlc():
httpserver.prepare()

# Simulate a Ctrl-C on the first call to `run`.
def raise_keyboard_interrupt(*args):
def raise_keyboard_interrupt(*args, **kwargs):
raise KeyboardInterrupt()

httpserver._connections.run = raise_keyboard_interrupt
httpserver._connections._selector.select = raise_keyboard_interrupt

serve_thread = threading.Thread(target=httpserver.serve)
serve_thread.start()
Expand Down

0 comments on commit 3e73dd6

Please sign in to comment.