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

Closing process stdin, stdout and stderr #23

Open
niklasf opened this issue Mar 25, 2015 · 4 comments
Open

Closing process stdin, stdout and stderr #23

niklasf opened this issue Mar 25, 2015 · 4 comments

Comments

@niklasf
Copy link

niklasf commented Mar 25, 2015

Hi.

There seams to be no "official" way to close the standard input, output and error streams of a Spur process. A hack like

def close_std_streams(process):
    try:
        process._process_stdin.close() # Local
    except AttributeError:
        process._stdin.close() # SSH

    process._io._handlers[0]._file_in.close()
    process._io._handlers[1]._file_in.close()

appears to work, but is there a better way or should there be some method to do that?

Best regards
Niklas

@mwilliamson
Copy link
Owner

Hello Niklas,

You're right in that this is a feature that I've not implemented, simply because it's not come up before. The simplest solution I can think of is to expose stdin, stdout and stderr attributes on the process object. Do you think calling close on any of them should call close any associated file objects? For instance, calling close on stdout should close stdout of the process, but should it also call close on any file objects hooked up to be piped from stdout?

@niklasf
Copy link
Author

niklasf commented Apr 4, 2015

Hi Michael,

today I noticed that my above hack is not sufficient. IOError: close() called during concurrent operation on the same file object. because the handler thread is still reading the output stream.

I am not sure what would be best here, yet. For orientation I'll check how subprocess.Popen does this.

@ninoles
Copy link

ninoles commented Aug 5, 2016

Somewhat related, I end up adding a shutdown_write method on the SshProcess object, that call either the shutdown_write method on channel. I agree with @niklasf about looking at subprocess.Popen for the behavior.

@ri0t
Copy link

ri0t commented Dec 16, 2019

I was trying hard to get a public key from wireguard until i found out that it needs stdin closed to operate, their syntax to do that with pipes is thus:
wg pubkey < secretkeyfile > publickeyfile
..which when running in a terminal only responds after "signaling" EOF on the input.

So, yeah, 👍 for adding a close operation for std*

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

4 participants