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

[Foxy] Handle signals within the asyncio loop. (#476) #506

Merged
merged 11 commits into from
Jul 7, 2021
Prev Previous commit
Next Next commit
Only try to wrap the fd in a socket on Windows (#498)
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
ivanpauno authored and hidmic committed Jun 29, 2021
commit 365402a4a636953d1a4118e849d51c5b0c44d514
10 changes: 3 additions & 7 deletions launch/launch/utilities/signal_management.py
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
import asyncio
from contextlib import ExitStack
import os
import platform
import signal
import socket
import threading
@@ -26,11 +27,6 @@
from typing import Tuple # noqa: F401
from typing import Union

try:
_WindowsError = WindowsError
except NameError:
_WindowsError = None


class AsyncSafeSignalManager:
"""
@@ -190,12 +186,12 @@ def __chain_wakeup_handle(self, wakeup_handle):
if isinstance(prev_wakeup_handle, socket.socket):
# Detach (Windows) socket and retrieve the raw OS handle.
prev_wakeup_handle = prev_wakeup_handle.detach()
if wakeup_handle != -1:
if wakeup_handle != -1 and platform.system() == 'Windows':
# On Windows, os.write will fail on a WinSock handle. There is no WinSock API
# in the standard library either. Thus we wrap it in a socket.socket instance.
try:
wakeup_handle = socket.socket(fileno=wakeup_handle)
except _WindowsError as e:
except WindowsError as e:
if e.winerror != 10038: # WSAENOTSOCK
raise
self.__prev_wakeup_handle = wakeup_handle