mySql and multiple connection for threads

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • johnny

    #1

    mySql and multiple connection for threads

    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()

  • johnny

    #2
    Re: mySql and multiple connection for threads

    Thank you VERY MUCH Dennis, for taking the time to explain to me.

    Comment

    • johnny

      #3
      Re: mySql and multiple connection for threads

      Another question I have is, let say you get an exception and I want to
      write all exception into a log file. There is one log file, and 5
      threads will be sharing. I need a way to lock it, write the log, and
      release the log file, so other threads can write to the logs. Can some
      one give me some pointers?

      Comment

      Working...