Use os._exit in the child instead of sys.exit.
diff --git a/src/portpicker.py b/src/portpicker.py index 10b373d..a887781 100644 --- a/src/portpicker.py +++ b/src/portpicker.py
@@ -280,7 +280,7 @@ for held_socket in bound_sockets: held_socket.close() finally: - sys.exit(0) + os._exit(0) def _pick_unused_port_without_server(bind_timeout=0):