Skip to content

Commit 6ad47a9

Browse files
committed
Append command's execution output instead of overwriting it when resuming a job.
1 parent e53b42d commit 6ad47a9

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

scripts/smart_worker.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import argparse
66
import subprocess
77
import logging
8+
import time as t
89

910
from smartdispatch import utils
1011
from smartdispatch.command_manager import CommandManager
@@ -44,10 +45,21 @@ def main():
4445
stdout_filename = os.path.join(args.logs_dir, uid + ".out")
4546
stderr_filename = os.path.join(args.logs_dir, uid + ".err")
4647

47-
with open(stdout_filename, 'w') as stdout_file:
48-
with open(stderr_filename, 'w') as stderr_file:
49-
stdout_file.write("# " + command + '\n')
50-
stderr_file.write("# " + command + '\n')
48+
stdout_already_exists = os.path.isfile(stdout_filename)
49+
stderr_already_exists = os.path.isfile(stderr_filename)
50+
51+
with open(stdout_filename, 'a') as stdout_file:
52+
with open(stderr_filename, 'a') as stderr_file:
53+
if not stdout_already_exists:
54+
stdout_file.write(t.strftime("## %Y-%m-%d %H:%M:%S ##\n"))
55+
else:
56+
stdout_file.write("# " + command + '\n')
57+
58+
if not stderr_already_exists:
59+
stderr_file.write(t.strftime("## %Y-%m-%d %H:%M:%S ##\n"))
60+
else:
61+
stderr_file.write("# " + command + '\n')
62+
5163
stdout_file.flush()
5264
stderr_file.flush()
5365

0 commit comments

Comments
 (0)