Skip to content

Capture stdout and stderr #1515

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

Closed
wants to merge 6 commits into from
Closed

Capture stdout and stderr #1515

wants to merge 6 commits into from

Conversation

rpkak
Copy link
Contributor

@rpkak rpkak commented Jul 14, 2021

Closes #886

Captures the stdout and the stderr of a job and makes it accessible using job.stdout ans job.stderr.

@codecov
Copy link

codecov bot commented Jul 14, 2021

Codecov Report

Attention: Patch coverage is 87.35632% with 11 lines in your changes missing coverage. Please review.

Project coverage is 95.49%. Comparing base (76ba690) to head (ae3ed94).
Report is 312 commits behind head on master.

Files with missing lines Patch % Lines
rq/worker.py 57.14% 6 Missing ⚠️
rq/job.py 93.61% 3 Missing ⚠️
tests/fixtures.py 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1515      +/-   ##
==========================================
- Coverage   95.59%   95.49%   -0.11%     
==========================================
  Files          46       46              
  Lines        7058     7145      +87     
==========================================
+ Hits         6747     6823      +76     
- Misses        311      322      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rpkak rpkak marked this pull request as ready for review July 14, 2021 20:25
@selwin
Copy link
Collaborator

selwin commented Jul 19, 2021

I like the idea of workers writing to stdout and stderr, think should be achievable by tweaking the default logging configuration.

I'm not sure about saving stdout and stderr it to Redis though, it may significantly increase storage usage.

@rpkak
Copy link
Contributor Author

rpkak commented Jul 24, 2021

I made this optional now.

You have to activate this using queue.enqueue(func, capture_stdout=True, capture_stderr=True).

@kuraga
Copy link

kuraga commented Dec 4, 2021

Any news?

@Hongyuy
Copy link

Hongyuy commented Mar 24, 2022

looking forward to using this feature.

@caiobsilva
Copy link

any reason as to why this PR hasn't been merged?

@dberardo-com
Copy link

dberardo-com commented Jun 15, 2023

i could confirm that this PR works as expected, but the streams are not closed when the function has run till the end. is this by design ?

i need to use this workaround:

job=q.enqueue(test_loop, capture_stdout=True, capture_stderr=True, retry=Retry(max=1, interval=[.2, 1, 2]), iterations=6)
try:
    for line in iter(job._stdout.strio.readline, b''):
        if line:
            print(">>> " + line.rstrip())
        if job.is_finished and not job._stdout.strio.closed: job._stdout.strio.close()
except ValueError: pass
assert job._stdout.strio.closed and job.is_finished

@melizeche
Copy link

@rpkak This feature would solve many issues for me, there's any way that I can help to get this approved and merged?

@selwin
Copy link
Collaborator

selwin commented Jun 26, 2024

@melizeche you can use Python’s logging mechanism to log to stdout and stderr

@kuraga
Copy link

kuraga commented Jun 27, 2024

you can use Python’s logging mechanism to log to stdout and stderr

We would want to log per-job, I think?

@rpkak rpkak closed this Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Capturing stdout output of jobs
7 participants