Skip to content

Commit 18e9401

Browse files
committed
fix: avoid no found pids
1 parent afac95e commit 18e9401

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

bigcodebench/eval/utils.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def safe_kill(pid, sig):
141141
else:
142142
print(f"Prevented attempt to kill PID {pid} with signal {sig}")
143143
except ProcessLookupError:
144-
print(f"Process {pid} does not exist.")
144+
pass
145145

146146
def safe_killpg(pgid, sig):
147147
if pgid == current_pgid or pgid in {os.getpgid(pid) for pid in child_pids}:
@@ -224,15 +224,18 @@ def safe_exec(*args, **kwargs):
224224
for pid in child_pids:
225225
try:
226226
os.kill(pid, signal.SIGTERM)
227-
os.waitpid(pid, 0)
227+
# Wait for a short time to see if the process terminates
228+
for _ in range(10): # Wait up to 1 second
229+
time.sleep(0.1)
230+
if os.waitpid(pid, os.WNOHANG) != (0, 0):
231+
break
232+
else:
233+
# If the process didn't terminate, try SIGKILL
234+
os.kill(pid, signal.SIGKILL)
228235
except ProcessLookupError:
229236
pass # Process already terminated
230237
except Exception as e:
231-
print(f"Error terminating process {pid}: {e}")
232-
try:
233-
os.kill(pid, signal.SIGKILL)
234-
except Exception:
235-
pass
238+
print(f"Error handling process {pid}: {e}")
236239

237240
os.kill = original_kill
238241
os.killpg = original_killpg

0 commit comments

Comments
 (0)