Skip to content
Closed
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
32 changes: 25 additions & 7 deletions python/pyspark/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,26 @@ def handle_sigterm(*args):

# Initialization complete
try:
poller = None
if os.name == "posix":
# select.select has a known limit on the number of file descriptors
# it can handle. We use select.poll instead to avoid this limit.
poller = select.poll()
fd_reverse_map = {0: 0, listen_sock.fileno(): listen_sock}
poller.register(0, select.POLLIN)
poller.register(listen_sock, select.POLLIN)

while True:
try:
ready_fds = select.select([0, listen_sock], [], [], 1)[0]
except select.error as ex:
if ex[0] == EINTR:
continue
else:
raise
if poller is not None:
ready_fds = [fd_reverse_map[fd] for fd, _ in poller.poll(1000)]
else:
try:
ready_fds = select.select([0, listen_sock], [], [], 1)[0]
except select.error as ex:
if ex[0] == EINTR:
continue
else:
raise

if 0 in ready_fds:
try:
Expand Down Expand Up @@ -208,6 +220,9 @@ def handle_sigterm(*args):

if pid == 0:
# in child process
if poller is not None:
poller.unregister(0)
poller.unregister(listen_sock)
listen_sock.close()

# It should close the standard input in the child process so that
Expand Down Expand Up @@ -256,6 +271,9 @@ def handle_sigterm(*args):
sock.close()

finally:
if poller is not None:
poller.unregister(0)
poller.unregister(listen_sock)
shutdown(1)


Expand Down