I have some very simple python code that sets up a job queue, piping to the linux batch
command:
import subprocess
for j in range(1,17):
process = subprocess.Popen('/bin/sh', '-c', f'python test.py {j} | batch')
process.communicate()
print(process.returncode)
When I run this, the print(process.returncode)
line prints 0
which means success.
The script being called in the subprocess, test.py
, just writes a quick txt file so nothing resource consuming:
import sys
with open(f'{sys.argv[1]}.txt', 'w') as f:
f.write('hello')
This code creates 16 jobs and appears to run them all at once (batch
is kinda pointless in what I'm doing at the moment since the server never reaches a load where it needs to queue jobs, but I'm just learning right now). Immediately after running it, when I type atq
in the terminal, I can see that none of the jobs are running (no =
or b
), but they also don't clear the queue despite the seeming success given that they write the text files and give me a returncode of 0
. What could be the reason for them to not clear the queue? If it's a hidden error, how would I go about getting that output?
57 Wed Aug 16 18:37:00 2023
48 Wed Aug 16 18:37:00 2023
58 Wed Aug 16 18:37:00 2023
49 Wed Aug 16 18:37:00 2023
56 Wed Aug 16 18:37:00 2023
60 Wed Aug 16 18:37:00 2023
51 Wed Aug 16 18:37:00 2023
59 Wed Aug 16 18:37:00 2023
50 Wed Aug 16 18:37:00 2023
55 Wed Aug 16 18:37:00 2023
54 Wed Aug 16 18:37:00 2023
47 Wed Aug 16 18:37:00 2023
52 Wed Aug 16 18:37:00 2023
61 Wed Aug 16 18:37:00 2023
53 Wed Aug 16 18:37:00 2023
62 Wed Aug 16 18:37:00 2023
...