-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanager.py
37 lines (32 loc) · 1.01 KB
/
manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
import time
import subprocess
def check(file,urls):
f = open(file,'a+')
f.close()
f_pid = open('pid.txt','a')
cmd = r"python C:\Users\Houking\Desktop\downloader\dblp\downloader.py %s" % urls
sub = subprocess.Popen(cmd)
f_pid.write('%d %d\n' % (os.getpid(), sub.pid))
f_pid.flush()
while True:
start_time = os.path.getmtime(file)
if sub.stdout:
print(sub.stdout.readlines())
timeout = 60
while timeout>0:
time.sleep(1)
timeout-=1
if os.path.getmtime(file)==start_time:
if time.time()-os.path.getmtime(file)>1800:
print("All have been downloaded!")
sub.kill()
break
print("########## restart downloading #########")
sub.kill()
sub = subprocess.Popen(cmd)
f_pid.write('%d %d\n' % (os.getpid(),sub.pid))
f_pid.flush()
f_pid.close()
if __name__=="__main__":
check('pdf.txt','./url/doi_0.txt')