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

Make sure that the RPC thread is stopped if the child exits unexpectedly #136

Merged
merged 1 commit into from
Oct 8, 2024
Merged
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
13 changes: 12 additions & 1 deletion src/unoserver/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def signal_handler(signum, frame):
raise

if self.xmlrcp_server is not None:
self.xmlrcp_server.shutdown()
self.stop() # Ensure the server stops

signal.signal(signal.SIGTERM, signal_handler)
signal.signal(signal.SIGINT, signal_handler)
Expand Down Expand Up @@ -189,6 +189,14 @@ def stop(self):
self.libreoffice_process.terminate()
if self.xmlrcp_server is not None:
self.xmlrcp_server.shutdown()
# Make a dummy connection to unblock accept() - otherwise it will
# hang indefinitely in the accept() call.
# noinspection PyBroadException
try:
with socket.create_connection((self.interface, int(self.port)), timeout=1):
pass
except Exception:
pass # Ignore any except
if self.xmlrcp_thread is not None:
self.xmlrcp_thread.join()

Expand Down Expand Up @@ -278,6 +286,9 @@ def main():

process.wait()

# The RPC thread needs to be stopped before the process can exit
server.stop()

if args.libreoffice_pid_file:
# Remove the PID file
os.unlink(args.libreoffice_pid_file)
Expand Down
Loading