-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
osproc: execProcess and startProcess hang forever (stuck on streams.readLine) #9953
Comments
note: since execProcess wraps startProcess, it's only worth looking at -d:case2 here's backtrace with lldb:
|
Do you have any easily reproducible sample that only requires POSIX tools? Not all of us have Sublime Text to test this with. |
These APIs are heavily used. By testament, on OSX too. Nothing hangs. Maybe it's the space in your path? |
i'm not making it up :)
var p = startProcess(command = cmd, options={poStdErrToStdOut, poEvalCommand})
let sub = outputStream(p)
let f = FileStream(sub).f
c_exec4(f)
|
@alaviss > Do you have any easily reproducible sample that only requires POSIX tools? Not all of us have Sublime Text to test this with. not yet but pretty sure it's not specific to |
that could explain the bug ; it's still a bug IMO as both D and C++ work in that case. |
Here's my speculation: I think a partial version of |
Here's my PoC:
import terminal
if isatty stdin:
echo "Hi!"
else:
while true: discard
import osproc
let ret = execProcess("./child", options={poStdErrToStdOut}) This will hang indefinitely unless |
@alaviss thanks for the reply; but passing /Users/timothee/git_clone/nim/Nim/lib/pure/osproc.nim(360) execProcess but I'm guessing you mean the code is osproc would need to implement this, correct?
|
Yes, that's why I propose a `poParentStdin` instead to allow forwarding only stdin. `poParentStreams` will forward both stdin and stdout, so you can't capture the output.
|
In https://dlang.org/phobos/std_process.html
seems both simpler and more flexible than what we have in osproc: proc startProcess(command: string; workingDir: string = ""; args: openArray[string] = []; env: StringTableRef = nil; options: set[ProcessOption] = {poStdErrToStdOut}) (i'm taling only about aspect of selecting stdin/stdout/stderr) |
Not sure if #8648 is related. |
I agree the process API needs to be reworked. I've filed a similar issue here: |
I have this problem too: on nimforum. |
Is there any workaround or alternative library for getting a setup like this to work currently? Or are we stuck until the API is reworked? |
I've solved this issue and other problems related to osproc (eg #7999) by doing a full rewrite inspired from D's |
So what is the API that you've arrived at? I'm interested :) |
@timotheecour, would you post your new code as a github repo? Perhaps the community can help to develop the Windows version and to integrate it with the async libraries. I'd like to have good process management support in our Chronos library for example. |
i also wished independent parent streams, so this would be good :O |
This one is not related to #8648. In this case the compiler generates too much output blocks because the pipe is full. |
I wrote a tool that makes heavy use of |
I am writing a CLI application that uses stdin, stdout and stderr heavily. it also executes a lot of child processes, which also use them. without |
finally found a workaround that works for me! It is essential to close let process = osproc.startProcess(
command = "child-cmd",
args = [],
env = nil,
options = {poUsePath})
process.inputStream.close() # NOTE **Essential** - This prevents hanging/freezing when reading stdout below
process.errorStream.close() # NOTE **Essential** - This prevents hanging/freezing when reading stdout below
let (lines, exCode) = process.readLines()
process.close() # This is probably not required |
/cc @Araq @dom96 this is a serious usability blocker
I'm on OSX
any
osproc
routine that captures stdout gets stuck forever.nim c -r -d:case1 $timn_D/tests/nim/all/t0040.nim
nim c -r -d:case2 $timn_D/tests/nim/all/t0040.nim
other languages don't have this problem
in D:
in C++:
clang++ -o /tmp/z01 -std=c++14 -g -ferror-limit=7 $timn_D/tests/nim/all/t0041.cpp
note
execCmdEx
#9634The text was updated successfully, but these errors were encountered: