[ python-Bugs-1469557 ] FTP modue functions are not re-entrant, give odd exceptions

SourceForge.net noreply at sourceforge.net
Thu Apr 13 02:13:57 CEST 2006


Bugs item #1469557, was opened at 2006-04-12 17:13
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1469557&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Bruce (brucepeterson)
Assigned to: Nobody/Anonymous (nobody)
Summary: FTP modue functions are not re-entrant,give odd exceptions

Initial Comment:
 If I define a class using the Thread and FTP moudles, 
start a process which gathers FTP responses, 
additional calls to the class may have the responses 
of the thread instead of the main loop (or vice versa)
  This causes weird and unexpected exceptions from the 
ftplib.

  For instance I get the following error when the 
thread process does a pwd() function
error_reply: 213 34603008  

  The "213" reply is a response from the main process 
size() function

---------
Code
---------
from time import sleep
from threading import Thread

class ftpMachine(Thread, ftplib.FTP):
    def __init__(self, svr, user, passwd):
        Thread.__init__(self)
        ftplib.FTP.__init__(self, svr, user, passwd)
        
    def run(self):
        for x in xrange(20):
            output="Thread -"+str(self.nlst())[:30]
            print output
            sleep (0.0100)

def main():
    aCon = ftpMachine("LocalFTP", "user", "")
    aCon.start()
    for x in xrange(20):
        output = "Main -- " + str(aCon.size("File"))
        print output  
        sleep (0.010)

Workround:
  Rewrite code to create a third worker thread for 
response isolation?  Don't know that this would solve 
the problem.


---------------
Exception example
---------------

Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Python24\lib\threading.py", line 442, in 
__bootstrap
    self.run()
  File "dualFTPIssue.py", line 17, in run
    output  = "Thread output " + str(self.nlst())[:30]
+" ..."
  File "C:\Python24\lib\ftplib.py", line 448, in nlst
    self.retrlines(cmd, files.append)
  File "C:\Python24\lib\ftplib.py", line 396, in 
retrlines
    conn = self.transfercmd(cmd)
  File "C:\Python24\lib\ftplib.py", line 345, in 
transfercmd
    return self.ntransfercmd(cmd, rest)[0]
  File "C:\Python24\lib\ftplib.py", line 321, in 
ntransfercmd
    host, port = self.makepasv()
  File "C:\Python24\lib\ftplib.py", line 299, in 
makepasv
    host, port = parse227(self.sendcmd('PASV'))
  File "C:\Python24\lib\ftplib.py", line 566, in 
parse227
    raise error_reply, resp
error_reply: 213 34603008

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1469557&group_id=5470


More information about the Python-bugs-list mailing list