I have a python script that waits for the creation of a file and then runs some analysis on it.
for input_path in expected_paths:
while not os.path.exists(input_path):
time.sleep(0.5)
run_analysis(input_path)
The files must be created while the script is running.
I am running this in a conda environemnt on my PC, it works for the first few files (usually 10-30 at a time) and then seemingly gets stuck in the loop (I have an output that gets printed when run_analysis happens and that stops being printed out; run_analysis also creates an output file for each input_path, which is also not created when the script gets stuck.
There is no error or warning, the script seems to keep running in the terminal window, despite the fact that the file in input_path has already been created.
If I stop the script, and start it running again, it performs run_analysis on all the files that exist so far, including the one it got “stuck” on, and keeps going as expected until getting stuck on another file 10-30 files later.
When I stop the script by pressing Ctrl-C or Ctrl-S, the Keyboard Interrupt traceback indicates it was in the middle of the time.sleep(0.5) function, as I’d expect if it were stuck in the while loop.
I’ve tried both running this script in Anaconda Powershell, and switching to cmd.exe to run the script. There doesn’t seem to be much of a difference. Unselecting “Quick Edit Mode” and “Insert Mode” in Anaconda Powershell Properties (based on solutions/explanations here and here) also does not solve the problem (neither does pressing Ctrl-Q while the script is stuck).
I strongly suspect the issue is something PC-specific, but have no idea where to start or what it might be. Any insight would be really appreciated – thank you!
mossomest is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.