I have read multiple posts and many articles detailing that scipts in a cron job need to keep the environment variables necessary to run inside the script itself due to the opening of shells within cron. My situation is unique in that my path variables are all being set as discussed, which in turn will successfully call the pysaunter python egg using subprocess.call(), but it seems to break down from there. This causes the whole process to break in a cron job.
For clarity, here are the steps I refer to:
1) cronjob calls run_test.py -n foo
2) run_test.py sets the environment variables correctly
(cur_shell_path=sys.path (converted to proper path string, not shown here)
my_env= os.environ.copy()
my_env["PATH"] = my_env["PATH"] + cur_shell_path)
3) run_test.py calls subprocess.call("pysaunter -m foo -v", env=my_env, shell=True)
The output of step 3 shows that it is finding the egg and successfully starts to load the necessary modules from pysaunter, but then it breaks when attempting to find a directory used to modify pysaunter. The error reads :
ImportError: no module named helpers
I have attempted adding this path to the environment multiple times but it never seems to find the directory that contains helpers.py. The command pysaunter -m foo -v
works normally when called from an interactive shell.
I couldn't find much help on pysaunter, so I assume that too much pysaunter specifics would be unneccessary here. If however you know more about pysaunter, please let me know if you require more information. I am not sure what to share.
I have also read many posts discussing the ability to change the default behavior of a shell by editing the .profile/.bash_profile. I attempted to find a place that would make my path variables globally accessible, but I couldn't find anything. I am not sure how this is done, and it may fix my problem, so if you know anything about that please let me know.
Final note, this is running on Mac 10.7.5.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…