Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

319 Windows Hang on Exit #320

Merged
merged 6 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading