forked from jonashaag/bjoern
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix jonashaag#77: Don't abort running requests on ^C
The graceful shutdown is achieved by stopping the accept and signal watchers. This way, we're not accepting any more clients and the main loop ends as soon as all currently processed requests have been worked off. This patch also ports the libev API calls from libev v3 to v4.
- Loading branch information
Showing
2 changed files
with
61 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import time | ||
import threading | ||
import bjoern | ||
import os | ||
import signal | ||
import httplib | ||
|
||
HOST = ('127.0.0.1', 9000) | ||
|
||
request_completed = False | ||
|
||
def application(environ, start_response): | ||
start_response('200 ok', []) | ||
yield "chunk1" | ||
os.kill(os.getpid(), signal.SIGINT) | ||
yield "chunk2" | ||
yield "chunk3" | ||
global request_completed | ||
request_completed = True | ||
|
||
|
||
def requester(): | ||
conn = httplib.HTTPConnection(*HOST) | ||
conn.request("GET", "/") | ||
conn.getresponse() | ||
|
||
|
||
threading.Thread(target=requester).start() | ||
try: | ||
bjoern.run(application, *HOST) | ||
except KeyboardInterrupt: | ||
assert request_completed | ||
else: | ||
raise RuntimeError("Didn't receive KeyboardInterrupt") |