Skip to content

Instantly share code, notes, and snippets.

@konverner
Created October 12, 2024 09:33
Show Gist options
  • Save konverner/405516c08f4f8e1978499143ab7deba7 to your computer and use it in GitHub Desktop.
Save konverner/405516c08f4f8e1978499143ab7deba7 to your computer and use it in GitHub Desktop.
run the script for N seconds for M arguments
import subprocess
import time
timeout = 40 # Set timeout to 40 seconds
with open('items.txt', 'r') as file:
items = file.read().strip().split('\n')
for item in items:
item = item.strip() # Clean up any extra whitespace
if item: # Ensure the project name is not empty
print(f"Processing item: {item}")
command = ['python', 'main.py', '--item', item]
try:
subprocess.run(command, timeout=timeout)
except subprocess.TimeoutExpired:
print(f"Subprocess for item '{item}' timed out and was terminated after {timeout} seconds")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment