Skip to content
Open
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
12 changes: 12 additions & 0 deletions src/meshcat/servers/zmqserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import base64
import os
import re
import signal
import sys
import subprocess
import multiprocessing
Expand Down Expand Up @@ -406,10 +407,21 @@ def main():
if results.open:
webbrowser.open(bridge.web_url, new=2)

def cleanup():
bridge.zmq_socket.close()
bridge.context.destroy()

# Make sure also kill results in socket being closed otherwise ZMQbg/Reaper and IO processes might stay open
atexit.register(cleanup)
signal.signal(signal.SIGTERM, cleanup)
signal.signal(signal.SIGINT, cleanup)

try:
bridge.run()
except KeyboardInterrupt:
pass
finally:
cleanup()

if __name__ == '__main__':
main()
7 changes: 7 additions & 0 deletions src/meshcat/visualizer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import signal
import webbrowser
import umsgpack
import numpy as np
Expand Down Expand Up @@ -79,6 +80,12 @@ def get_image(self, w, h):
img = Image.open(io.BytesIO(img_bytes))
return img

def close(self):
self.zmq_socket.close()
self.context.destroy()
if self.server_proc is not None:
self.server_proc.kill()
self.server_proc.wait()

def srcdoc_escape(x):
return x.replace("&", "&").replace('"', """)
Expand Down