Skip to content

Commit

Permalink
319 Windows Hang on Exit (#320)
Browse files Browse the repository at this point in the history
* Blank line formatting.

* Try signal handling in waitress.

* Remove unrecognised SIGQUIT.

* Don't try to handle Unix signals on Windows.

* Forceful kill.

* Cater for everybody.
  • Loading branch information
trisyoungs committed Mar 14, 2024
1 parent e280755 commit 202bf0e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
19 changes: 17 additions & 2 deletions backend/src/jv2backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,26 @@ def load(self):
options["log-level"] = "INFO"
GUnicornApplication(jv2app, options).run()


global server
def go_waitress(jv2app: Flask, args):
from waitress import serve
from waitress.server import create_server
import signal
global server

# serve(jv2app, listen=args.bind, channel_timeout=args.timeout)

# signal handler, to do something before shutdown service
def handle_sig(sig, frame):
logging.warning(f"Got signal {sig}, now close worker...")
# worker.close()
server.close()

serve(jv2app, listen=args.bind, channel_timeout=args.timeout)
for sig in (signal.SIGINT, signal.SIGTERM):
signal.signal(sig, handle_sig)

server = create_server(jv2app, listen=args.bind, channel_timeout=args.timeout)
server.run()


def go():
Expand Down
10 changes: 9 additions & 1 deletion frontend/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ Backend::Backend(const QCommandLineParser &args) : process_()
if (args.isSet(CLIArgs::DebugBackend))
backendArgs << "-d";
if (args.isSet(CLIArgs::UseWaitress))
{
backendArgs << "-w";
waitressBackend_ = true;
}

process_.setArguments(backendArgs);
process_.setProcessChannelMode(QProcess::ForwardedChannels);
Expand Down Expand Up @@ -77,7 +80,12 @@ void Backend::stop()
// Gracefully inform the backend to quit
createRequest(createRoute("shutdown"));

process_.terminate();
// Send the TERM signal to gunicorn, but send the KILL signal to waitress. Dontcha just love cross-platform development?
if (waitressBackend_)
process_.kill();
else
process_.terminate();

process_.waitForFinished();
}

Expand Down
2 changes: 2 additions & 0 deletions frontend/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class Backend : public QObject
QProcess process_;
// Network manager
QNetworkAccessManager manager_;
// Whether we are using waitress-serve backend over gunicorn
bool waitressBackend_{false};

private:
// Return the backend bind address
Expand Down

0 comments on commit 202bf0e

Please sign in to comment.