Created
October 12, 2024 09:33
-
-
Save konverner/405516c08f4f8e1978499143ab7deba7 to your computer and use it in GitHub Desktop.
run the script for N seconds for M arguments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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