Comments (6)
This seems like a good feature to have here. I would indeed call it something other than tee
though, since that does feel a bit jargony.
from iocapture.jl.
I'm going to play around a little and see if I come up with something that works
from iocapture.jl.
For context: https://discourse.julialang.org/t/a-tee-option-for-iocapture/108642
from iocapture.jl.
Well, here's a start:
output = IOBuffer()
temp = IOBuffer()
buffer_redirect_task = @async begin
write(temp, pipe)
temp_data = take!(temp)
write(output, temp_data)
write(default_stdout, temp_data)
end
This seems to capture the data from the pipe while also passing it through the normal stdout
.
Is this a good idea, or does this have the potential to block something or slow things down at a low level? If there's an expert on the IO internals that can sign off on this, I can easily build that into a full PR.
from iocapture.jl.
This might work, too, and avoid the allocation of temp_data
?
output = IOBuffer()
temp = IOBuffer()
buffer_redirect_task = @async begin
n_bytes = write(temp, pipe)
seek(temp, 0)
write(output, read(temp, n_bytes))
seek(temp, 0)
write(default_stdout, read(temp, n_bytes))
end
from iocapture.jl.
Ugh… neither of these actually works. I should have tested it on a longer-running calculation to start with. It seems like the writing to default_stdout
gets buffered until the task ends. I've tried adding a flush(default_stdout)
, too.
Update: this one works better:
bufsize = 128
buffer = Vector{UInt8}(undef, bufsize)
buffer_redirect_task = @async begin
while !eof(pipe)
nbytes = readbytes!(pipe, buffer, bufsize)
data = view(buffer, 1:nbytes)
write(output, data)
write(default_stdout, data)
end
end
from iocapture.jl.
Related Issues (10)
- iocapture -> capture, don't export
- Rename throwerrors -> rethrow HOT 1
- TagBot trigger issue HOT 6
- Set rethrow to false HOT 1
- Capturing output in multithreaded context HOT 1
- Fails to capture long output from C stdio HOT 3
- Hang when captureing output from MathLink HOT 7
- Limit captured output HOT 3
- Declare as "stable" HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from iocapture.jl.