'can't open file : [Errno 2] No such file or directory
I get the following error when subprocess calls the process newtest.py. The code run as a daemon. When I started the daemon the process was called, it worked fine and did run 8 processes before started giving the error and then the error occurs at every call. The error is
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python: can't open file 'newtest.py': [Errno 2] No such file or directory
the code is below:
for index,row in enumerate(jobs):
if index <= new_jobs :
dirs=row[0]
dirName=os.path.join(homeFolder,dirs)
logFile=os.path.join(dirName,(dirs+".log"))
proc=subprocess.Popen(["/opt/local/bin/python2.6","newtest.py",dirs],stdout=open(logFile,'a',0),stderr=open(logFile,'a',0))
proId= proc.pid
I tried using the full path to newtest.py but it gives the same error. Any suggestions? Many Thanks!
Solution 1:[1]
Try:
subprocess.Popen(['/opt/local/bin/python2.6','/FULL/PATH/TO/FILE/newtest.py'],stdout=subprocess.PIPE)
Does that work? removed parameters and what not.
Also, can you do a:
f = open('/FULL/PATH/newtest.py')
print f
Solution 2:[2]
I don't remember if I've ever been affected by this on a Linux system, but here I am on MacOS with the same error.
I think I've solved it; you should change into the directory you are in in your forked process. I'm in something like /Users/me/dev/project/ and running bin/my-daemon start.
In code, at the top of the daemonize method, I call cwd = os.getcwd() to a variable and then call os.chdir(cwd) in the fork.
It's been over half an hour and usually the daemon would have raised that No such file or directory error by now, but it hasn't.
This may not be an issue if your pid file is using an absolute path (/var/run/my.pid), but I'm using it relative to my project since I may not have write permissions and the user may specify where to write it.
Edit: Just realized how old this question was and the OP's code might reference a different issue. Here is the daemon code, slightly modified, that I was using:
https://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
I do hope this answer helps someone.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 |
