forked from luyishisi/Anti-Anti-Spider
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
在程序调用phantomjs的时候,可能因phantomjs死锁导致的进程僵死。。 | ||
测试进程下设置超时时间。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |