diff options
author | Chris McDonough <chrism@plope.com> | 2015-05-14 02:57:35 -0400 |
---|---|---|
committer | Chris McDonough <chrism@plope.com> | 2015-05-14 02:57:35 -0400 |
commit | 8d90c4fa61a6d3120a0f260651c91fd5cab453b4 (patch) | |
tree | 22f31ae73fc76756f51d529e9795fe1f4df9ef3e | |
parent | 228d068484b1fe253f35c4e367a5886332a0ed48 (diff) | |
download | waitress-8d90c4fa61a6d3120a0f260651c91fd5cab453b4.tar.gz |
dont translate KeyboardInterrupt in worker threads to thread.interrupt_main()feature.exit-from-thread
-rw-r--r-- | waitress/server.py | 16 | ||||
-rw-r--r-- | waitress/task.py | 7 | ||||
-rw-r--r-- | waitress/tests/fixtureapps/procexit.py | 4 | ||||
-rw-r--r-- | waitress/tests/test_functional.py | 2 |
4 files changed, 12 insertions, 17 deletions
diff --git a/waitress/server.py b/waitress/server.py index 8d0ba68..ade7b46 100644 --- a/waitress/server.py +++ b/waitress/server.py @@ -157,23 +157,23 @@ class BaseWSGIServer(logging_dispatcher, object): self.channel_class(self, conn, addr, self.adj, map=self._map) def run(self): + exitcode = 0 try: self.asyncore.loop( timeout=self.adj.asyncore_loop_timeout, map=self._map, use_poll=self.adj.asyncore_use_poll, ) + except (asyncore.ExitNow, SystemExit): + exitcode = 0 except KeyboardInterrupt: - # note that this is the codepath that will be executed both during - # an actual ctrl-C of a foregrounded program, when any task code - # raises KeyboardInterrupt in a thread, or when any subthread of - # this process calls thread.interrupt_main() + # note that this is the codepath that will be executed when SIGINT + # is sent to the main thread, when an actual ctrl-C is pressed on + # the console, or when thread.interrupt_main() is called from a + # subthread exitcode = 1 - except (SystemExit, asyncore.ExitNow): - # note that this is the codepath that will be executed when SIGTERM - # is sent to the main thread + finally: self.task_dispatcher.shutdown() - exitcode = 0 return exitcode def pull_trigger(self): diff --git a/waitress/task.py b/waitress/task.py index 2df0989..d6d18a7 100644 --- a/waitress/task.py +++ b/waitress/task.py @@ -83,13 +83,6 @@ class ThreadedTaskDispatcher(object): 'Exception when servicing %r' % task) if isinstance(e, JustTesting): break - except KeyboardInterrupt as e: - # we translate a KeyboardInterrupt exception raised in a - # thread to mean call thread.interrupt_main(), which will - # cause a KeyboardInterrupt to be raised in the main - # process (eventually causing the process to exit). - thread.interrupt_main() - break finally: with self.thread_mgmt_lock: self.stop_count -= 1 diff --git a/waitress/tests/fixtureapps/procexit.py b/waitress/tests/fixtureapps/procexit.py index daf04d3..081d479 100644 --- a/waitress/tests/fixtureapps/procexit.py +++ b/waitress/tests/fixtureapps/procexit.py @@ -1,2 +1,4 @@ +import thread + def app(environ, start_response): # pragma: no cover - raise KeyboardInterrupt + thread.interrupt_main() diff --git a/waitress/tests/test_functional.py b/waitress/tests/test_functional.py index bd1a2c2..260595a 100644 --- a/waitress/tests/test_functional.py +++ b/waitress/tests/test_functional.py @@ -1358,7 +1358,7 @@ class ProcExitTests(TcpTests, unittest.TestCase): def tearDown(self): self.stop_subprocess() - def test_keyboard_interrupt_exits_main_process(self): + def test_thread_interrupt_main_exits_main_process(self): to_send = "GET / HTTP/1.0\n\n" to_send = tobytes(to_send) self.connect() |