import os
import urllib
from datetime import datetime
import workerpool
class DownloadJob(workerpool.Job):
def __init__(self, fa):
self.fa = fa
def run(self):
f = open(self.fa + '.txt','w')
f.write('Example Note.......')
f.close()
pool = workerpool.WorkerPool(size=5)
def workfile():
range1 = 51
range2 = 102
fam1 = 555
fam2 = 833
ranges = range2 -range1
fams = fam2 -fam1
workname = "Python"
path = os.getcwd()
os.system('mkdir ' + str(workname))
sTime = datetime.now()
for a in range(ranges + 1):
os.chdir(path + '\\' + str(workname))
os.system('mkdir ' + str(range1 + a))
os.chdir(path + '\\' + str(workname) + '\\' + str(range1 + a))
for b in range(fams + 1):
fa = str(fam1 + b)
job = DownloadJob(fa)
pool.put(job)
pool.shutdown()
pool.wait()
print 'Elapsed Time: %s' % (datetime.now() - sTime)
z = open('info.txt','w')
z.write('Elapsed Time: %s' % (datetime.now() - sTime))
z.close()
os.chdir(path + '\\' + str(workname))
tumSure = open('info.txt','w')
tumSure.write('Elapsed All Time: %s' % (datetime.now() - sTime))
tumSure.close()
print 'All Time: %s' % (datetime.now() - sTime)
print 'Workname : %s downloaded.' % (workname)
quit()
workfile()
hi all ,
i have a code as above and i want to use thread logic for creating file but range1 folder start 51 it creates txt file name with 555.txt to 833.txt ... and than it creates folder with name 52 but stops and not creates 555.txt to 833.txt file....
it think it stops because
pool.shutdown()
pool.wait()
that code ..if i delete this line it creates folder but fams....
pls help...
i have to give my work on time....