Skip to content

Commit

Permalink
Only try to wrap the fd in a socket on Windows (#498)
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
  • Loading branch information
ivanpauno authored and hidmic committed Jun 29, 2021
1 parent 4fd532a commit 365402a
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions launch/launch/utilities/signal_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import asyncio
from contextlib import ExitStack
import os
import platform
import signal
import socket
import threading
Expand All @@ -26,11 +27,6 @@
from typing import Tuple # noqa: F401
from typing import Union

try:
_WindowsError = WindowsError
except NameError:
_WindowsError = None


class AsyncSafeSignalManager:
"""
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 365402a

Please sign in to comment.