If I want to run unrelated tasks and output stdout over the network how would I capture stdout in a module without another module stealing it?
As I see it there is only one Base.stdout, which is the default for println. As a backup there is also Core.stdout, but I think this should not be touched. How would one implement println per module to use a module owned stdout.
module A const stdout = redirect_stdout() print() = println("Mod A") end module B const stdout = redirect_stdout() print() = println("Mod B") end A.print() B.print() readline(A.stdout) # is empty readline(B.stdout) # Mod A readline(A.stdout) # Mod B
Another idea is writing to a file and overwriting print functions, but maybe there is a more elegant way.
module A const out = mktemp() print(txt) = Base.print(out,txt) function generate() print("test1") println("test2") @show a=3 end function get() seek(out,0) read(out,String) end println(txt) = Base.println(out,txt) end A.generate() # a = 3 = 3 # 3 A.get() # "test1test2\n"