threading+ftp+import => block

Panard panard at backzone.net
Mon Jul 24 09:26:58 EDT 2006


Hi,
I'm experiencing a strange problem while trying to manage a ftp connection
into a separate thread.

I'm on linux, python 2.4.3

Here is a test :
------ ftp_thread.py ------
import ftplib
import threading
import datetime

class test( threading.Thread ) :
        ftp_conn = ftplib.FTP("localhost","user","pass")
        def run( self ) :
                print self.ftp_conn.pwd()
                self.ftp_conn.dir("/")
                print datetime.date.today()
def t() :
        t = test()
        t.start()
        t.join()
t()
-------

If I do :
$ python ftp_thread.py
/
drwxrwsr-x   2 panard   ftp          4096 Jul 24 12:48 archives
2006-07-24
==> Works perfectly

But :
$ python
>>> import ftp_thread
/
<program block>

For a strange reason, I've tried to add theses lines before the 't()' call :

ftp_conn = ftplib.FTP("localhost","user","pass")
ftp_conn.dir("/")

And then, when calling t(), self.ftp_conn.dir("/") shows the list ! (I guess
a problem of globals()/import .. ?)
But... the program now blocks just before displaying today date...

I guess I'm doing something really wrong with threads.. but I don't know
what...

Any hints?

Thanks

Panard



More information about the Python-list mailing list