Skip to content
Open
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
37 changes: 33 additions & 4 deletions src/clusterfuzz/_internal/system/new_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,49 @@ def wait_process(process,
result = ProcessResult()
is_windows = environment.platform() == 'WINDOWS'

def create_timeout_timer(interval, function, args):
Comment thread
g-ortuno marked this conversation as resolved.
"""Helper to create a timer that logs timeout info.

This function takes the same arguments as threading.Timer.

Args:
interval: The delay in seconds before the timer action is executed.
function: The function to be called when the timer expires.
args: The arguments to be passed to the function.

Returns:
A threading.Timer object.
"""

def target():
binary_name = os.path.basename(process.command[0])
action_fn = args[0]
logs.info(f"TIMEOUT: Terminating {binary_name} after {interval} seconds "
f"(using {action_fn.__name__}).")
function(*args)

return threading.Timer(interval, target)

# On Windows, terminate() just calls Win32 API function TerminateProcess()
# which is equivalent to process kill. So, skip terminate_before_kill.
if terminate_before_kill and not is_windows:
first_timeout_function = process.terminate

# Use a second timer to send the process kill.
second_timer = threading.Timer(timeout + terminate_wait_time, _end_process,
[process.kill, result])
second_timer = create_timeout_timer(
timeout + terminate_wait_time,
_end_process,
[process.kill, result],
)
else:
first_timeout_function = process.kill
second_timer = None

first_timer = threading.Timer(timeout, _end_process,
[first_timeout_function, result])
first_timer = create_timeout_timer(
timeout,
_end_process,
[first_timeout_function, result],
)

output = None
start_time = time.time()
Expand Down
Loading