Navigation Menu

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

runtime processing of stderr from a command #7

Closed
tgianko opened this issue Sep 7, 2017 · 1 comment
Closed

runtime processing of stderr from a command #7

tgianko opened this issue Sep 7, 2017 · 1 comment

Comments

@tgianko
Copy link

tgianko commented Sep 7, 2017

Hi,

I need to run an external command and at the same time to process the output as it is generated.

In this setting, the external command is the producer (with async=True and capture_stderr=True), and my program is the consumer. The stderr should be consumed by a function in a thread that pulls from the shared resource until the command finishes (is_finished=True).

In my first attempt, I passed a StringIO to ExternalCommand.stderr_file. My idea was to keep everything in memory, without external files. This does not work as ExternalCommand tries to get the fileno from the file object. StringIO does not support that... so exception. I looked at the code of CachedStream and I couldn't see an obvious reason why to retrive the fileno and file name from the file object. Wouldn't be better to keep a local copy of the file object and write on it?

In my second attempt, I thought to use a FIFO file. However, here there is another shortcoming. The built-in function open returns such a file object only when the producer opens the same FIFO for writing operations. Until then, the open blocks the consumer. This prevents me to pass the file object to ExternalCommand.stderr_file. An alternative could be os.open that allows to open with the flag os.O_NONBLOCK, but this won't work as the returned descriptor is an int.

Do you have any idea on how to go around that? I would like to avoid to use regular files and actually I'd prefer to keep everything in memory. StringIO is actually my favorite one, but FIFO are also fine.

@xolox
Copy link
Owner

xolox commented Jan 21, 2018

Hi Giancarlo and thanks for the feedback. I've just released executor 18.1 which adds the buffered property that can be used to disable the buffering of output to temporary files. The documentation contains an example that reads the output of an external command in realtime. I hope this helps!

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