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

_bg doesn't work if not being assigned #139

Closed
dmd opened this issue May 4, 2013 · 6 comments
Closed

_bg doesn't work if not being assigned #139

dmd opened this issue May 4, 2013 · 6 comments

Comments

@dmd
Copy link

dmd commented May 4, 2013

sh.sleep(5, _bg=True)   # blocks for 5 seconds

x = sh.sleep(5, _bg=True)   # returns immediately
@amoffat
Copy link
Owner

amoffat commented May 4, 2013

Are you running this in a python shell by chance? The python shell will try to evaluate the return value of a function, if you're not assigning it to a variable, thereby causing sleep to block.

@dmd
Copy link
Author

dmd commented May 4, 2013

Yes, I am. Ok, that makes sense, thanks. Is there any way to get a background process started by sh to persist after the python program has ended? I get "Exception in thread Thread-1 (most likely raised during interpreter shutdown)".

@amoffat
Copy link
Owner

amoffat commented May 4, 2013

So I looked at the code. It should be possible, in theory, to do:

import sh
sh.nohup.sleep(60, _bg=True)

And a sleep process should exist in the background. The problem is this line, which adds the spawned process to a list of processes to be killed on script exit, if persist is False. persist will always be False though, because it looks like a feature that didn't get fully built.

If you want to add this for yourself and everyone else, I would remove the persist keyword argument on OProc, and in its place, use self.call_args["persist"], then add the persist special argument here. This would allow you to do:

import sh
sh.nohup.sleep(60, _bg=True, _persist=True)

@dmd
Copy link
Author

dmd commented May 5, 2013

I've decided not to use sh after all but rather to rework my code so I don't have to shell out in the first place, so I'm not going to bother. Sorry...

@amoffat
Copy link
Owner

amoffat commented Sep 8, 2013

spawned processes now persist after exit by default and ignore SIGHUP

@amoffat amoffat closed this as completed Sep 8, 2013
@JonathanRRogers
Copy link

Unfortunately, this change seems to make foreground subprocesses persist after the Python sh process as well as background, which is very surprising compared with /bin/sh.

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

3 participants