-
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid to run Python event loop in WSGI (#443)
- Loading branch information
Showing
9 changed files
with
406 additions
and
235 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
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,45 @@ | ||
import signal | ||
import sys | ||
import threading | ||
|
||
from ._granian import WorkerSignal, WorkerSignalSync | ||
|
||
|
||
def set_main_signals(interrupt_handler, reload_handler=None): | ||
signals = [signal.SIGINT, signal.SIGTERM] | ||
if sys.platform == 'win32': | ||
signals.append(signal.SIGBREAK) | ||
|
||
for sig in signals: | ||
signal.signal(sig, interrupt_handler) | ||
|
||
if reload_handler is not None and sys.platform != 'win32': | ||
signal.signal(signal.SIGHUP, reload_handler) | ||
|
||
|
||
def set_loop_signals(loop): | ||
signal_event = WorkerSignal() | ||
|
||
def signal_handler(signum, frame): | ||
signal_event.set() | ||
|
||
signals = [signal.SIGINT, signal.SIGTERM] | ||
|
||
try: | ||
for sigval in signals: | ||
loop.add_signal_handler(sigval, signal_handler, sigval, None) | ||
except NotImplementedError: | ||
for sigval in signals: | ||
signal.signal(sigval, signal_handler) | ||
|
||
return signal_event | ||
|
||
|
||
def set_sync_signals(): | ||
signal_event = WorkerSignalSync(threading.Event()) | ||
|
||
def signal_handler(signum, frame): | ||
signal_event.set() | ||
|
||
set_main_signals(signal_handler) | ||
return signal_event |
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
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
Oops, something went wrong.