nim-chronos icon indicating copy to clipboard operation
nim-chronos copied to clipboard

Implement APIs for async process I/O

Open zah opened this issue 4 years ago • 8 comments

Chronos needs an API for launching sub-processes and interacting with their standard input and output through AsyncPipe. Additional APIs may be added for controlling process groups and for automatically terminating sub-processes when their parent dies.

zah avatar Feb 20 '20 22:02 zah

I can port Golden's system for this if you want. It handles the buffering without any problems AFAIK, but it will be good to give it more testing.

disruptek avatar Feb 29 '20 20:02 disruptek

Can you clarify what "Golden" is?

zah avatar Mar 05 '20 10:03 zah

Golden is a poor-man's hyperfine that I wanted for monitoring compilation performance and the code I'm thinking of looks like this:

https://github.com/disruptek/golden/blob/master/src/golden/invoke.nim

It calls startProcess and then uses the selectors to monitor the streams and whether the process has terminated. After removing the code to monitor cpu/clock time, the implementation is very simple.

disruptek avatar Mar 05 '20 17:03 disruptek

Well, @cheatfate also has his own process I/O library based on asyncdispatch: https://github.com/cheatfate/asynctools/blob/master/asynctools/asyncproc.nim

Your chances of merging PRs here will be significantly enhanced if you take his existing code into consideration :)

I also hope that @timotheecour is going to release his private lib for process I/O inspired by D's interfaces. We don't want to repeat the same mistakes as the std lib when designing this API.

zah avatar Mar 05 '20 17:03 zah

Can you explain how asyncproc is insufficient to meet the requirement? Does it merely need to be copied and massaged into Chronos?

disruptek avatar Mar 05 '20 17:03 disruptek

asyncproc requires some procedures which chronos do not have, tricks with RegisterWaitForSingleObject, https://github.com/nim-lang/Nim/blob/devel/lib/pure/asyncdispatch.nim#L1002-L1018

cheatfate avatar Mar 05 '20 18:03 cheatfate

Also AsyncPipe is not needed actually we can use StreamTransport instances.

cheatfate avatar Mar 05 '20 18:03 cheatfate

can this implementation be reused here? https://github.com/yglukhov/asyncthreadpool/blob/main/asyncthreadpool/private/pipes.nim

bernardoaraujor avatar Jul 12 '21 14:07 bernardoaraujor

#374

arnetheduck avatar May 23 '23 14:05 arnetheduck