+'''
+Created on Mar 7, 2017
+
+@author: shinchulwoo
+'''
+
+import os
+import threading
+from tic.utils.file import make_dirs, decompress_gzip, copyfile_flock
+from tic.utils.grabber import myurlgrab2
+import contextlib
+
+class MyThread(threading.Thread):
+ def __init__(self, name, url):
+ threading.Thread.__init__(self)
+ self.name = name
+ self.url = url
+ self.__suspend = False
+ self.__exit = False
+ self.__path = './test/thread/'
+ self.__cachepath = './test/thread/cache'
+ def run(self):
+ print('%s Thread start !!!' % self.name)
+ path=os.path.join(self.__path, self.name)
+ make_dirs(path)
+ filename=os.path.join(path, os.path.basename(self.url))
+ myurlgrab2(self.url, filename)
+ print('%s Thread download file !!!' % self.name)
+ # Check if file compressed or not
+ if filename.endswith(".gz"):
+ decompress_filename = os.path.splitext(filename)[0]
+ filename = decompress_gzip(filename, decompress_filename)
+ print('%s Thread decompress file !!!' % self.name)
+
+ cachefile = os.path.join(self.__cachepath, os.path.basename(filename))
+ copyfile_flock(filename, cachefile)
+ print('%s Thread finish !!!' % self.name)
+
+ def mySuspend(self):
+ self.__suspend = True
+ def myResume(self):
+ self.__suspend = False
+ def myExit(self):
+ self.__exit = True
+
+if __name__ == '__main__':
+ url = ''
+ th1 = MyThread('th1', url)
+ th1.start()
+# th2 = MyThread('th2', url)
+# th2.start()
\ No newline at end of file