9 from tic.utils.file import make_dirs, decompress_gzip, copyfile_flock
10 from tic.utils.grabber import myurlgrab2
13 class MyThread(threading.Thread):
14 def __init__(self, name, url):
15 threading.Thread.__init__(self)
18 self.__suspend = False
20 self.__path = './test/thread/'
21 self.__cachepath = './test/thread/cache'
23 print('%s Thread start !!!' % self.name)
24 path=os.path.join(self.__path, self.name)
26 filename=os.path.join(path, os.path.basename(self.url))
27 myurlgrab2(self.url, filename)
28 print('%s Thread download file !!!' % self.name)
29 # Check if file compressed or not
30 if filename.endswith(".gz"):
31 decompress_filename = os.path.splitext(filename)[0]
32 filename = decompress_gzip(filename, decompress_filename)
33 print('%s Thread decompress file !!!' % self.name)
35 cachefile = os.path.join(self.__cachepath, os.path.basename(filename))
36 copyfile_flock(filename, cachefile)
37 print('%s Thread finish !!!' % self.name)
42 self.__suspend = False
46 if __name__ == '__main__':
48 th1 = MyThread('th1', url)
50 # th2 = MyThread('th2', url)