Skip to content

Commit

Permalink
Revert "Improve shutdown robustness when using --reload or multipro…
Browse files Browse the repository at this point in the history
…cessing (#620)" (#756)

This reverts commit fdb89e9
  • Loading branch information
euri10 committed Aug 28, 2020
1 parent df81b16 commit ff4af12
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 27 deletions.
11 changes: 0 additions & 11 deletions uvicorn/subprocess.py
Expand Up @@ -4,7 +4,6 @@
"""
import multiprocessing
import os
import signal
import sys

multiprocessing.allow_connection_pickling()
Expand Down Expand Up @@ -60,13 +59,3 @@ def subprocess_started(config, target, sockets, stdin_fileno):

# Now we can call into `Server.run(sockets=sockets)`
target(sockets=sockets)


def shutdown_subprocess(pid):
"""
Helper to attempt cleanly shutting down a subprocess. May fail with an exception.
* pid - Process identifier.
"""
os.kill(pid, signal.SIGINT)
os.waitpid(pid, 0)
9 changes: 1 addition & 8 deletions uvicorn/supervisors/basereload.py
Expand Up @@ -5,7 +5,7 @@

import click

from uvicorn.subprocess import get_subprocess, shutdown_subprocess
from uvicorn.subprocess import get_subprocess

HANDLED_SIGNALS = (
signal.SIGINT, # Unix signal 2. Sent by Ctrl+C.
Expand All @@ -22,19 +22,12 @@ def __init__(self, config, target, sockets):
self.sockets = sockets
self.should_exit = threading.Event()
self.pid = os.getpid()
self.process = None
self.reloader_name = None

def signal_handler(self, sig, frame):
"""
A signal handler that is registered with the parent process.
"""
if self.process is not None:
try:
shutdown_subprocess(self.process.pid)
except Exception as exc:
logger.error(f"Could not stop child process {self.process.pid}: {exc}")

self.should_exit.set()

def run(self):
Expand Down
9 changes: 1 addition & 8 deletions uvicorn/supervisors/multiprocess.py
Expand Up @@ -5,7 +5,7 @@

import click

from uvicorn.subprocess import get_subprocess, shutdown_subprocess
from uvicorn.subprocess import get_subprocess

HANDLED_SIGNALS = (
signal.SIGINT, # Unix signal 2. Sent by Ctrl+C.
Expand All @@ -28,13 +28,6 @@ def signal_handler(self, sig, frame):
"""
A signal handler that is registered with the parent process.
"""

for process in self.processes:
try:
shutdown_subprocess(process.pid)
except Exception as exc:
logger.error(f"Could not stop child process {process.pid}: {exc}")

self.should_exit.set()

def run(self):
Expand Down

0 comments on commit ff4af12

Please sign in to comment.