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

Migrate to subprocess.call #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

silentmoose
Copy link

the current implementation of popen does not allow for the wait() so we do not have any errors. With subprocess.call it includes the wait anyway. Also popen is depreciated to subprocess.call

Popen is depreciated wait() which is needed for bugfix

wbond#45

Switched to subprocess.call
Migrated to subprocess.call
@@ -85,7 +85,8 @@ def get():
else:
ps = 'ps -eo comm | grep -E "gnome-session|ksmserver|' + \
'xfce4-session" | grep -v grep'
wm = [x.replace("\n", '') for x in os.popen(ps)]
wm = [x.replace("\n", '') for x in subprocess.call(ps)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os.popen returns a readable file object with the matching running session commands (e.g. gnome-session).

subprocess.call returns the exit code. Instead of this, we will need to use subprocess.PIPE or subprocess.check_output with a split

https://docs.python.org/3.4/library/os.html#os.popen

https://docs.python.org/3.3/library/subprocess.html#subprocess.call

@twolfson
Copy link
Collaborator

While there was a deprecation notice in Python 2.7, it seems to have disappeared in Python 3.3/3.4:

https://docs.python.org/2.7/library/os.html#os.popen

https://docs.python.org/3.3/library/os.html#os.popen

https://docs.python.org/3.4/library/os.html#os.popen

Aside from that, can you elaborate more on the wait() problem you are encountering?

@wbond
Copy link
Owner

wbond commented Jun 14, 2015

So a defunct/zombie process on Unix is caused by a parent process that forks a child, but never checks the return code. To make this go away, I believe we just need to call os.wait().

https://en.wikipedia.org/?title=Zombie_process
https://docs.python.org/2/library/os.html#os.wait

@twolfson
Copy link
Collaborator

As documented in Python 2.7, we could also use handle.close() on the file descriptor we opened:

https://docs.python.org/2.7/library/os.html#os.popen

handle = os.popen(ps)
wm = [x.replace("\n", '') for x in handle]
handle.close()

@wbond
Copy link
Owner

wbond commented Jun 14, 2015

We jus need to make sure we look at 2.6 since that is what ST2 uses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants