Changeset 487:e68724ac688d

Show
Ignore:
Timestamp:
2006-02-06 22:39:20 (4 years ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
convert_revision:
svn:778c30c8-61e0-0310-89d4-fe2f97a467b2/trunk@506
Message:
Added an optional parameter `also_files` to `FTPHost.keep_alive`
and documented it in `ftputil.txt`.
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • ftputil.py

    r484 r487  
    103103           'PermanentError', 'ParserError', 'FTPIOError', 
    104104           'RootDirError', 'FTPHost'] 
    105 __version__ = '2.0.4' 
     105__version__ = '2.1b' 
    106106 
    107107 
     
    249249        return self.file(path, mode) 
    250250 
    251     def keep_alive(self): 
     251    def keep_alive(self, also_files=True): 
    252252        """ 
    253253        Do something without side effects to keep the connection to 
    254254        the server. This can be used to prevent broken connections due 
    255255        to server timeouts. 
     256 
     257        If the parameter `also_files` is a true value, which is the 
     258        default, propagate the connection refresh to all associated 
     259        open file-like objects. In multi-threaded applications, you 
     260        may want to set `also_files` to `False` and call the 
     261        `keep_alive` method of the file-like objects individually. 
    256262        """ 
    257263        # just prevent loss of the connection, so discard the result 
    258264        self.getcwd() 
     265        # refresh also connections of associated file-like objects 
     266        if also_files: 
     267            for host in self._children: 
     268                host._file.keep_alive() 
    259269 
    260270    def close(self): 
  • ftputil.txt

    r485 r487  
    654654  and use of remote file-like objects. 
    655655 
    656 - ``keep_alive()`` 
     656.. _`FTPHost.keep_alive`: 
     657 
     658- ``keep_alive(also_files=True)`` 
    657659 
    658660  Do something without side effects to hold the connection to the FTP 
    659661  server. This should be used to prevent server timeouts after several 
    660662  minutes of inactivity. 
     663 
     664  Note that not only an ``FTPHost`` object but also *each* of the 
     665  file-objects made from it has its own connection to the FTP server, 
     666  so all of the connections must be kept alive. Use the default 
     667  setting, ``True``, for ``also_files`` to propagate the refresh to 
     668  all open file-like objects made from this ``FTPHost`` instance. 
     669 
     670  However, be careful with the default parameter in multi-threaded 
     671  applications. 
    661672 
    662673 
     
    711722  server. This should be used to prevent server timeouts after several 
    712723  minutes of inactivity. 
     724 
     725  Note that not only an ``FTPHost`` object but also *each* of the 
     726  file-objects made from it has its own connection to the FTP server, 
     727  so all of the connections must be kept alive. Use the 
     728  `FTPHost.keep_alive`_ to refresh all connections at once. 
    713729 
    714730 
     
    816832- Timeouts of individual child sessions currently are not handled. 
    817833  This is only a problem if your ``FTPHost`` object or the generated 
    818   ``FTPFile`` objects are inactive for about ten minutes or longer. A 
    819   workaround is to keep the respective connections busy, e. g. call 
    820   ``getcwd`` on ``FTPHost`` objects or ``write("")`` on remote 
    821   file-like objects. 
     834  ``FTPFile`` objects are inactive for about ten minutes or longer. 
     835  As a workaround, you can use the ``keep_alive`` methods of 
     836  ``FTPHost`` objects and remote file-like objects. 
    822837 
    823838- Until now, I haven't paid attention to thread safety. In principle,