From c6f50ecc51f68378a08c62bfb8e944d1a586b1c4 Mon Sep 17 00:00:00 2001 From: mehrdadn Date: Fri, 21 Feb 2020 13:15:11 -0800 Subject: [PATCH] setpgrp fix (#7250) --- python/ray/services.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/python/ray/services.py b/python/ray/services.py index 9a798d93e..4357d9a81 100644 --- a/python/ray/services.py +++ b/python/ray/services.py @@ -1,4 +1,5 @@ import collections +import errno import json import logging import multiprocessing @@ -282,10 +283,10 @@ def get_node_ip_address(address="8.8.8.8:53"): # connection. s.connect((ip_address, int(port))) node_ip_address = s.getsockname()[0] - except Exception as e: + except OSError as e: node_ip_address = "127.0.0.1" # [Errno 101] Network is unreachable - if e.errno == 101: + if e.errno == errno.ENETUNREACH: try: # try get node ip address from host name host_name = socket.getfqdn(socket.gethostname()) @@ -582,11 +583,15 @@ def start_reaper(): try: os.setpgrp() except OSError as e: - logger.warning("setpgrp failed, processes may not be " - "cleaned up properly: {}.".format(e)) - # Don't start the reaper in this case as it could result in killing - # other user processes. - return None + if e.errno == errno.EPERM and os.getpgrp() == os.getpid(): + # Nothing to do; we're already a session leader. + pass + else: + logger.warning("setpgrp failed, processes may not be " + "cleaned up properly: {}.".format(e)) + # Don't start the reaper in this case as it could result in killing + # other user processes. + return None reaper_filepath = os.path.join( os.path.dirname(os.path.abspath(__file__)), "ray_process_reaper.py")