Skip to content

Commit

Permalink
发现进程调用phantomjs假死问题已经修复
Browse files Browse the repository at this point in the history
  • Loading branch information
luyishisi committed Jan 16, 2017
1 parent 920523b commit fec51e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions 9.phantomjs/timeout/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
在程序调用phantomjs的时候,可能因phantomjs死锁导致的进程僵死。。
测试进程下设置超时时间。
19 changes: 19 additions & 0 deletions 9.phantomjs/timeout/timeout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import subprocess
from threading import Timer
import time

kill = lambda process: process.kill()

cmd = ["ping", "www.google.com"]
ping = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

my_timer = Timer(5, kill, [ping])
try:
my_timer.start()
stdout, stderr = ping.communicate()
#print stderr
print time.ctime()
finally:
print time.ctime()
my_timer.cancel()

0 comments on commit fec51e5

Please sign in to comment.