https://github.com/gorakhargosh/watchdog/pull/225/files added a setsid
call when running a command via auto-restart
. This command is not available on OS X leading to:
$ watchmedo auto-restart -- MY-COMMAND-HERE
Traceback (most recent call last):
File "/Users/nickolay/temp-env/bin/watchmedo", line 9, in <module>
load_entry_point('watchdog==0.8.3', 'console_scripts', 'watchmedo')()
File "/Users/nickolay/temp-env/lib/python2.7/site-packages/watchdog/watchmedo.py", line 566, in main
parser.dispatch()
File "/Users/nickolay/temp-env/lib/python2.7/site-packages/argh/helpers.py", line 55, in dispatch
return dispatch(self, *args, **kwargs)
File "/Users/nickolay/temp-env/lib/python2.7/site-packages/argh/dispatching.py", line 174, in dispatch
for line in lines:
File "/Users/nickolay/temp-env/lib/python2.7/site-packages/argh/dispatching.py", line 277, in _execute_command
for line in result:
File "/Users/nickolay/temp-env/lib/python2.7/site-packages/argh/dispatching.py", line 231, in _call
result = function(namespace_obj)
File "/Users/nickolay/temp-env/lib/python2.7/site-packages/watchdog/watchmedo.py", line 541, in auto_restart
handler.start()
File "/Users/nickolay/temp-env/lib/python2.7/site-packages/watchdog/tricks/__init__.py", line 147, in start
self.process = subprocess.Popen(self.command)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Judging from https://docs.python.org/3/library/subprocess.html
If you need to modify the environment for the child use the env parameter rather than doing it in a preexec_fn. The start_new_session parameter can take the place of a previously common use of preexec_fn to call os.setsid() in the child.
...this might be doable in pure python (at least on Unix). Since watchdog supports Python 2.6, it probably would have to use preexec_fn
instead of start_new_session
.
Changing https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/tricks/__init__.py#L125 in the following two places works for me on OS X 10.9.5:
< 141 self.command = ['setsid'] + command
> 141 self.command = command
146 def start(self):
< 147 self.process = subprocess.Popen(self.command, preexec_fn=os.setsid)
> 147 self.process = subprocess.Popen(self.command)
I didn't test with the original case from PR 225 and this might work incorrectly on Windows (os.setsid
seems unsupported there, and I'm not sure how os.killpg
works there).
This is already addressed by #329.
Right, sorry, don't know how I missed that issue.
python package is still not updated 馃槶
yes, still hitting this on osx
auto-restart is completely broken on Windows, too.
os.setsid is not available there.
So I just found my own response on #329 from almost a month ago when looking into this issue for a colleague, so I'd figure I'd mention what I did to fix it, for the next time I happen upon this page...
pip install git+https://github.com/gorakhargosh/watchdog.git
Most helpful comment
So I just found my own response on #329 from almost a month ago when looking into this issue for a colleague, so I'd figure I'd mention what I did to fix it, for the next time I happen upon this page...
pip install git+https://github.com/gorakhargosh/watchdog.git