Problem in dealing with timeout and ftplib? (py2.3a2)

Steve Holden sholden at holdenweb.com
Tue Feb 25 19:19:46 CET 2003


"Chen" <chenpuqing at 163.net> wrote in message
news:b3g73d$1ps6$1 at mail.cn99.com...
> Hi, everyone!
>
> I'm writting an ftp resource scanner. The program starts many threads and
> each one searchs in an IP range. If a host cannot be connected in a
> specified time, say, 10 seconds, then the thread should go to the next
host.
>
> I've implemented the  function with python-2.2.2 and Timothy O'Malley's
> timeoutsocket.py (many thanks to him :-) . The program works very well.
But
> now, since python-2.3 provides such a builtin function in socket.py, I
want
> to change to it.
>
> But, I find the `sock' attribute of ftplib.FTP object is `None' before the
> connection is established. So I can't use the `.sock.settimeout' method
> before I use `.connect' method of FTP object.
>
> By a little tracing, I found the `sock' attribute is created in the
> `connect' method of the FTP object. So I can't use the timeout function in
> connection.
>
> I think I must change the file ftplib.py. But, are there any other
> solutions?
>

Well, truthfully it was probably never a very good idea to go poking around
in the implementation details of the FTP object. The recommended way to get
the right timeout using O'Malley's module was to use its
"setdefaulttimeout()" function to establish a default timeout far any
sockets created without knowledge of the library.

Isn't there an equivalent to this in the new socket module?

regards
--
Steve Holden                                  http://www.holdenweb.com/
Python Web Programming                 http://pydish.holdenweb.com/pwp/
Register for PyCon now!            http://www.python.org/pycon/reg.html







More information about the Python-list mailing list