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

Capturing output in multithreaded context #14

Open
tlienart opened this issue May 10, 2022 · 1 comment
Open

Capturing output in multithreaded context #14

tlienart opened this issue May 10, 2022 · 1 comment

Comments

@tlienart
Copy link

tlienart commented May 10, 2022

Hello,

I currently use IOCapture as follows and it works well:

try
    captured = IOCapture.capture() do
        include_string(...)
    end
    # ... processing of captured ...
catch e
    # ...
end

I'd like to be able to do this in a multi-threaded context where these calls potentially happen on separate threads. I can add a ReentrantLock and do

lock(l)
try
   captured[k] = IOCapture.capture() do ... end
catch
   ...
finally
    unlock(l)
end

but this amounts to doing these evaluations sequentially as far as I understand. Is there a better way to capture output of separate threads with IOCapture?

Thanks


Note: I also asked this question in the Suppressor repo (JuliaIO/Suppressor.jl#45) not sure which one of the two would be more amenable to doing this.

@mortenpi
Copy link
Member

mortenpi commented May 11, 2022

Under the hood, both IOCapture and Suppressor work basically the same way, so I think they're equally amenable. The basic workhorses are the redirect_stdout and redirect_stderr functions, but I am not sure how well they handle being called from separate threads in parallel. But it would be nice if IOCapture would just work in a multihreaded context.

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

No branches or pull requests

2 participants