How do you create multiple connection in the treads. Lets say I will
have at most 5 threads and I want to create at most 5 connections. If
I create a connection in the "worker method", does it create connection
for each threads.
def worker(tq):
while True:
host, e = tq.get()
c = ftplib.FTP(host )
c.connect()
try:
c.login()
p = os.path.basenam e(e)
download_dir = r'H:/ftp_download/'
ps_dir = r'H:/ftp_download/'
filename = download_dir+p
fp = open(filename, 'wb')
try: c.retrbinary('R ETR %s' % e, fp.write)
finally: fp.close()
finally: c.close()
if (p.lower().ends with('.ps') ):
partFileName = p.split('.', 1)
movedFile = download_dir + p
#movedFile = p
finalFile = ps_dir + partFileName[0]+'.pdf'
encode_cmd = r'ps2pdf '+ movedFile + ' '+ finalFile
os.system(encod e_cmd)
conn = adodb.NewADOCon nection('mysql' )
conn.Connect('l ocalhost', 'temp', 'temp', 'temp')
sql = r"update file where file_path='"+p+ "' set
pdf_file_path=' " +finalFile+"'"
cursor = conn.Execute(sq l)
rows = cursor.Affected _Rows()
tq.task_done()
have at most 5 threads and I want to create at most 5 connections. If
I create a connection in the "worker method", does it create connection
for each threads.
def worker(tq):
while True:
host, e = tq.get()
c = ftplib.FTP(host )
c.connect()
try:
c.login()
p = os.path.basenam e(e)
download_dir = r'H:/ftp_download/'
ps_dir = r'H:/ftp_download/'
filename = download_dir+p
fp = open(filename, 'wb')
try: c.retrbinary('R ETR %s' % e, fp.write)
finally: fp.close()
finally: c.close()
if (p.lower().ends with('.ps') ):
partFileName = p.split('.', 1)
movedFile = download_dir + p
#movedFile = p
finalFile = ps_dir + partFileName[0]+'.pdf'
encode_cmd = r'ps2pdf '+ movedFile + ' '+ finalFile
os.system(encod e_cmd)
conn = adodb.NewADOCon nection('mysql' )
conn.Connect('l ocalhost', 'temp', 'temp', 'temp')
sql = r"update file where file_path='"+p+ "' set
pdf_file_path=' " +finalFile+"'"
cursor = conn.Execute(sq l)
rows = cursor.Affected _Rows()
tq.task_done()
Comment