![](/img/trans.png)
[英]Nohup for Python script not working when running in the background with &
[英]python phanthomjs is not working with nohup
我正在使用phanthomjs運行selenium,如果我將其觸發為:
python my_script.py
但是當我嘗試使用nohup時:
nohup python my_script.py &
我收到以下錯誤:
selenium.common.exceptions.WebDriverException: Message: Service phantomjs unexpectedly exited. Status code was: 8
可能為時已晚,但是我只是在另一個代碼中遇到了類似的錯誤,所以我找到了解決方案。 因此,當您運行nohup時,程序的輸出將重定向到nohup.out,對於我來說,文件是這樣的:
Traceback (most recent call last):
me/fanar/.local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running
File "main.py", line 51, in <module>
Work()
File "main.py", line 41, in Work
TakeImage() # start o 16
File "main.py", line 9, in TakeImage
driver = webdriver.PhantomJS()
File "/home/fanar/.local/lib/python2.7/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 52, in __init__
self.service.start()
File "/home/fanar/.local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 96, in start
self.assert_process_still_running()
File "/home/fanar/.local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service phantomjs unexpectedly exited. Status code was: 1
解決方法是轉到
.local/lib/python2.7/site-packages/selenium/webdriver/common/service.py
並注釋掉行
self.assert_process_still_running()
指定參數對我有用:
driver = webdriver.PhantomJS(executable_path = '/usr/lib/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.