Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion billiard/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def get_fdmax(default=None):
"""
try:
return os.sysconf('SC_OPEN_MAX')
except:
except Exception:
pass
if resource is None: # Windows
return default
Expand Down
4 changes: 2 additions & 2 deletions billiard/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def _send_bytes(self, buf):

[ov.event], False, INFINITE)
assert waitres == WAIT_OBJECT_0
except:
except Exception:
ov.cancel()
raise
Comment on lines +318 to 320

Copilot AI Feb 26, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This except ensures ov.cancel() runs if the wait/write fails. With except Exception, KeyboardInterrupt/SystemExit during the wait will bypass cancellation, potentially leaving an overlapped I/O pending and leaking resources. Use except BaseException for the cancel-and-reraise pattern here.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please cross check this suggestion?

finally:
Expand Down Expand Up @@ -735,7 +735,7 @@ def accept(self):
try:
_winapi.WaitForMultipleObjects(
[ov.event], False, INFINITE)
except:
except Exception:
ov.cancel()
_winapi.CloseHandle(handle)
raise
Expand Down
4 changes: 2 additions & 2 deletions billiard/forkserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def connect_to_new_process(self, fds):
try:
reduction.sendfds(client, allfds)
return parent_r, parent_w
except:
except Exception:

Copilot AI Feb 26, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block is closing parent_r/parent_w on failure, but except Exception won’t run for KeyboardInterrupt/SystemExit, which can leak both fds. Use except BaseException for cleanup-and-reraise here, or move the closes to a finally that runs for all exception types when returning doesn’t happen.

Suggested change
except Exception:
except BaseException:

Copilot uses AI. Check for mistakes.
os.close(parent_r)
os.close(parent_w)
raise
Expand Down Expand Up @@ -124,7 +124,7 @@ def ensure_running(self):
args = [exe] + util._args_from_interpreter_flags()
args += ['-c', cmd]
spawnv_passfds(exe, args, fds_to_pass)
except:
except Exception:
os.close(alive_w)
raise
finally:
Expand Down
2 changes: 1 addition & 1 deletion billiard/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def shutdown(self, c):
try:
util.debug('Manager received shutdown message')
c.send(('#RETURN', None))
except:
except Exception:
import traceback
traceback.print_exc()
finally:
Expand Down
2 changes: 1 addition & 1 deletion billiard/popen_spawn_win32.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(self, process_obj):
spawn.get_executable(), cmd,
None, None, False, 0, None, None, None)
close_thread_handle(ht)
except:
except Exception:
_winapi.CloseHandle(rhandle)
raise

Expand Down
2 changes: 1 addition & 1 deletion billiard/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def _bootstrap(self):
sys.stderr.write(str(exc.args[0]) + '\n')
_maybe_flush(sys.stderr)
exitcode = 0 if isinstance(exc.args[0], str) else 1
except:
except Exception:
exitcode = 1
if not util.error('Process %s', self.name, exc_info=True):
Comment on lines +336 to 338

Copilot AI Feb 26, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exitcode is only set inside the try/except blocks. With except Exception, a KeyboardInterrupt/SystemExit raised anywhere in the outer try will skip the handlers and hit finally, where exitcode is referenced, causing an UnboundLocalError and masking the real reason for exit. Either initialize exitcode before the try and/or handle BaseException to ensure exitcode is always defined.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please cross check this @haosenwang1018

import traceback
Expand Down
2 changes: 1 addition & 1 deletion billiard/resource_sharer.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def _serve(self):
send(conn, destination_pid)
finally:
close()
except:
except Exception:
if not util.is_exiting():
sys.excepthook(*sys.exc_info())

Expand Down
4 changes: 2 additions & 2 deletions billiard/semaphore_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def ensure_running(self):
args = [exe] + util._args_from_interpreter_flags()
args += ['-c', cmd % r]
spawnv_passfds(exe, args, fds_to_pass)
except:
except Exception:
os.close(w)
raise
else:
Expand Down Expand Up @@ -121,7 +121,7 @@ def main(fd):
except Exception:
try:
sys.excepthook(*sys.exc_info())
except:
except Exception:
pass
finally:
# all processes have terminated; cleanup any remaining semaphores
Expand Down