Skip to content

Commit

Permalink
Merge pull request #26 from siKruger/master
Browse files Browse the repository at this point in the history
windows compat
  • Loading branch information
nanmu42 committed Mar 23, 2023
2 parents cd167e2 + 8f7e269 commit 080febf
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion robomasterpy/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import multiprocessing as mp
import queue
import signal
import platform
import socket
import sys
import time
Expand Down Expand Up @@ -240,6 +241,7 @@ def __init__(self):
Hub does not need parameters to initialize.
"""
self._mu = CTX.Lock()
self._block = True
with self._mu:
self._closed: bool = False
self._workers: List = []
Expand Down Expand Up @@ -300,6 +302,12 @@ def _build_worker_and_run(*args, **kwargs):
worker = worker_class(*args[1:], **kwargs)
worker()

def signal_handler(self, sig, frame):
"""
Handler for signals on windows
"""
self._block = False

def run(self):
"""
按注册顺序启动所有worker,阻塞主进程。
Expand All @@ -315,7 +323,17 @@ def run(self):
for worker in self._workers:
worker.start()

signal.sigwait((signal.SIGINT, signal.SIGTERM))
if platform.system() == "Windows":
# Register Handlers
signal.signal(signal.SIGINT, self.signal_handler)
signal.signal(signal.SIGTERM, self.signal_handler)
# Block until signal is received
while self._block:
time.sleep(1)
else:
# This only works on UNIX based Systems
signal.sigwait((signal.SIGINT, signal.SIGTERM))

self.close()
for worker in self._workers:
try:
Expand Down

0 comments on commit 080febf

Please sign in to comment.