tkf / emacs-ipython-notebook

IPython notebook client in Emacs
tkf.github.com/emacs-ipython-notebook/
GNU General Public License v3.0
548 stars 51 forks source link

Resolve tools/testein.py failure on OS X #120

Closed jhamrick closed 11 years ago

jhamrick commented 11 years ago

This should fix #119.

The arguments to ps do not translate nicely between versions, unfortunately, so it won't suffice to just have a single command. Instead, I changed it to try to run the GNU version first, and if that fails, then try the version that should work on OS X.

tkf commented 11 years ago

You don't need to use gnu options. Linux ps should have unix options. Let's keep the logic minimum, even if it requires a loop. This way, it should run on Linux if it runs on Mac. But It is sad that BSD ps does not have --ppid equivalent...

jhamrick commented 11 years ago

The issue I was trying to get around was that there is also no equivalent option for --no-headers. But actually, I realize that wouldn't matter if it's going to retrieve ppid and do the filtering in Python rather than with ps. I think then the correct command would be:

ps -e -o ppid,pid,command

And then check in the Python loop that ppid matches the target parent process.

jhamrick commented 11 years ago

Still failing with the invalid literal for int() with base 10: '' error. I think there are probably two spaces between the two pids, and so this is basically what's happening:

In [1]: "3423  2348  foo".split(' ', 2)
Out[1]: ['3423', '', '2348  foo']

Perhaps it should parse the ppid and pid out with a regex rather than using split? Something like this:

re.findall(r"^([0-9]+)[ ]+([0-9]+)[ ]+(.*)$", line)

tkf commented 11 years ago

Let's use None:

In [1]: "3423  2348  foo".split(None, 2)
Out[1]: ['3423', '2348', 'foo']

In [2]: str.split?
Type:       method_descriptor
Base Class: <type 'method_descriptor'>
String Form:<method 'split' of 'str' objects>
Namespace:  Python builtin
Docstring:
S.split([sep [,maxsplit]]) -> list of strings

Return a list of the words in the string S, using sep as the
delimiter string.  If maxsplit is given, at most maxsplit
splits are done. If sep is not specified or is None, any
whitespace string is a separator and empty strings are removed
from the result.
jhamrick commented 11 years ago

Oh, good idea, I had forgotten split could take None!

tkf commented 11 years ago

BTW, if you have extra power please squash commits into one commit :)

tkf commented 11 years ago

Merged. Thank you!

BTW, github does not notify when someone push to an existing pull request so please put some comment next time :)

jhamrick commented 11 years ago

Ah, sorry, I didn't realize it didn't send a notification. Thanks for letting me know, I'll be sure to comment next time!