Skip to content

Commit ea96413

Browse files
committed
Always write the datetime and the command in output logs.
1 parent e99a554 commit ea96413

File tree

3 files changed

+8
-18
lines changed

3 files changed

+8
-18
lines changed

scripts/smart_worker.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,13 @@ def main():
4545
stdout_filename = os.path.join(args.logs_dir, uid + ".out")
4646
stderr_filename = os.path.join(args.logs_dir, uid + ".err")
4747

48-
stdout_already_exists = os.path.isfile(stdout_filename)
49-
stderr_already_exists = os.path.isfile(stderr_filename)
50-
5148
with open(stdout_filename, 'a') as stdout_file:
5249
with open(stderr_filename, 'a') as stderr_file:
53-
if 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 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-
50+
stdout_file.write(t.strftime("## %Y-%m-%d %H:%M:%S ##\n"))
51+
stdout_file.write("# " + command + '\n')
6352
stdout_file.flush()
53+
stderr_file.write(t.strftime("## %Y-%m-%d %H:%M:%S ##\n"))
54+
stderr_file.write("# " + command + '\n')
6455
stderr_file.flush()
6556

6657
error_code = subprocess.call(command, stdout=stdout_file, stderr=stderr_file, shell=True)

smartdispatch/tests/test_smartdispatch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,4 @@ def test_log_command_line():
223223
assert_true(t.strftime("## %Y-%m-%d %H:%M:") in lines[6]) # Don't check second.
224224
assert_equal(lines[7], re.sub(r'(\[)([^\[\]]*\\ [^\[\]]*)(\])', r'"\1\2\3"', command_3))
225225

226-
shutil.rmtree(temp_dir)
226+
shutil.rmtree(temp_dir)

tests/test_smart_dispatch.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ def test_main_resume(self):
6060
assert_equal(len(open(running_commands_file).readlines()), 0)
6161
assert_equal(len(open(pending_commands_file).readlines()), len(commands))
6262

63-
# Test when batch_uid is a path instead of a jobname.
64-
# Setup
63+
# Test when batch_uid is a path instead of a jobname.
64+
# Setup
6565
call(self.launch_command, shell=True)
6666
batch_uid = os.path.join(self.logs_dir, os.listdir(self.logs_dir)[0])
6767

68-
# Simulate that some commands are in the running state.
68+
# Simulate that some commands are in the running state.
6969
path_job_commands = os.path.join(self.logs_dir, batch_uid, "commands")
7070
pending_commands_file = pjoin(path_job_commands, "commands.txt")
7171
running_commands_file = pjoin(path_job_commands, "running_commands.txt")
@@ -85,7 +85,6 @@ def test_main_resume(self):
8585
assert_equal(len(open(running_commands_file).readlines()), 0)
8686
assert_equal(len(open(pending_commands_file).readlines()), len(commands))
8787

88-
8988
def test_main_resume_only_pending(self):
9089
# SetUp
9190
call(self.launch_command, shell=True)

0 commit comments

Comments
 (0)