Python/Linux quit() does not terminate PhantomJS process · Issue #767 · SeleniumHQ/selenium https://github.com/SeleniumHQ/selenium/issues/767
signal.SIGKILL
def phantom_js_clean_up(): """Clean up Phantom JS. Kills all phantomjs instances, disregard of their origin. """ processes = subprocess.Popen(['ps', '-A'], stdout=subprocess.PIPE) out, err = processes.communicate() for line in out.splitlines(): if 'phantomjs' in line: pid = int(line.split(None, 1)[0]) os.kill(pid, signal.SIGKILL)
写入定时任务
import subprocess
import signal
import os
import time
processes = subprocess.Popen(['ps', '-A'], stdout=subprocess.PIPE)
out, err = processes.communicate()
for line in out.splitlines():
s = line.decode('utf-8')
if 'phantomjs' in s:
pid = int(s.split(None)[0])
# 日志
# 52 * * * * cd /home/data/crontab_chk_url/personas/trunk/plugins/spider/; python kill_phantomjs_whole_os.py &>> kill_phantomjs_whole_os_log;
print(signal, __file__, time.strftime('%Y%m%d_%H%M%S', time.localtime(time.time())))
os.kill(pid, signal.SIGKILL)
d = 9