Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix job runner stdout missing newline #6081

Merged
merged 8 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ requests_).
- Diquan Jabbour
- Shixian Sheng
- Utheri Wagura
- Maxime Rio
<!-- end-shortlog -->

(All contributors are identifiable with email addresses in the git version
Expand Down
2 changes: 2 additions & 0 deletions changes.d/6081.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix job submission when a batch of jobs is submitted to a runner that does
not return a newline with the job ID (did not affect built-in job runners).
2 changes: 1 addition & 1 deletion cylc/flow/job_runner_handlers/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def submit(cls, job_file_path, submit_opts):
exc.filename = "nohup"
return (1, None, str(exc))
else:
return (0, "%d\n" % (proc.pid), None)
return (0, str(proc.pid), None)
Copy link
Member

@hjoliver hjoliver Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This newline was compensating for the bug, pre-fix).



JOB_RUNNER_HANDLER = BgCommandHandler()
3 changes: 1 addition & 2 deletions cylc/flow/job_runner_handlers/documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,7 @@ def submit(
ret_code:
Subprocess return code.
out:
Subprocess standard output, note this should be newline
terminated.
Subprocess standard output.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(We now add the newline automatically)

err:
Subprocess standard error.

Expand Down
22 changes: 10 additions & 12 deletions cylc/flow/job_runner_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,10 @@ def jobs_kill(self, job_log_root, job_log_dirs):
self.OUT_PREFIX_SUMMARY, now, job_log_dir, ret_code))
# Note: Print STDERR to STDOUT may look a bit strange, but it
# requires less logic for the workflow to parse the output.
if err.strip():
for line in err.splitlines(True):
if not line.endswith("\n"):
line += "\n"
sys.stdout.write("%s%s|%s|%s" % (
self.OUT_PREFIX_CMD_ERR, now, job_log_dir, line))
for line in err.strip().splitlines():
sys.stdout.write(
f"{self.OUT_PREFIX_CMD_ERR}{now}|{job_log_dir}|{line}\n"
)

def jobs_poll(self, job_log_root, job_log_dirs):
"""Poll multiple jobs.
Expand Down Expand Up @@ -303,13 +301,13 @@ def jobs_submit(self, job_log_root, job_log_dirs, remote_mode=False,
sys.stdout.write("%s%s|%s|%d|%s\n" % (
self.OUT_PREFIX_SUMMARY, now, job_log_dir, ret_code, job_id))
for key, value in [("STDERR", err), ("STDOUT", out)]:
if value is None or not value.strip():
if value is None:
continue
for line in value.splitlines(True):
if not value.endswith("\n"):
value += "\n"
sys.stdout.write("%s%s|%s|[%s] %s" % (
self.OUT_PREFIX_COMMAND, now, job_log_dir, key, line))
for line in value.strip().splitlines():
sys.stdout.write(
f"{self.OUT_PREFIX_COMMAND}{now}"
f"|{job_log_dir}|[{key}] {line}\n"
)

def job_kill(self, st_file_path):
"""Ask job runner to terminate the job specified in "st_file_path".
Expand Down
Loading