Changeset 487:e68724ac688d
- 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:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r484
|
r487
|
|
| 103 | 103 | 'PermanentError', 'ParserError', 'FTPIOError', |
| 104 | 104 | 'RootDirError', 'FTPHost'] |
| 105 | | __version__ = '2.0.4' |
| | 105 | __version__ = '2.1b' |
| 106 | 106 | |
| 107 | 107 | |
| … |
… |
|
| 249 | 249 | return self.file(path, mode) |
| 250 | 250 | |
| 251 | | def keep_alive(self): |
| | 251 | def keep_alive(self, also_files=True): |
| 252 | 252 | """ |
| 253 | 253 | Do something without side effects to keep the connection to |
| 254 | 254 | the server. This can be used to prevent broken connections due |
| 255 | 255 | 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. |
| 256 | 262 | """ |
| 257 | 263 | # just prevent loss of the connection, so discard the result |
| 258 | 264 | 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() |
| 259 | 269 | |
| 260 | 270 | def close(self): |
-
|
r485
|
r487
|
|
| 654 | 654 | and use of remote file-like objects. |
| 655 | 655 | |
| 656 | | - ``keep_alive()`` |
| | 656 | .. _`FTPHost.keep_alive`: |
| | 657 | |
| | 658 | - ``keep_alive(also_files=True)`` |
| 657 | 659 | |
| 658 | 660 | Do something without side effects to hold the connection to the FTP |
| 659 | 661 | server. This should be used to prevent server timeouts after several |
| 660 | 662 | 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. |
| 661 | 672 | |
| 662 | 673 | |
| … |
… |
|
| 711 | 722 | server. This should be used to prevent server timeouts after several |
| 712 | 723 | 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. |
| 713 | 729 | |
| 714 | 730 | |
| … |
… |
|
| 816 | 832 | - Timeouts of individual child sessions currently are not handled. |
| 817 | 833 | 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. |
| 822 | 837 | |
| 823 | 838 | - Until now, I haven't paid attention to thread safety. In principle, |