@@ -401,7 +401,7 @@ def wait_for(fut, timeout, *, loop=None):
401401
402402@coroutine
403403def _wait (fs , timeout , return_when , loop ):
404- """Internal helper for wait() and _wait_for ().
404+ """Internal helper for wait() and wait_for ().
405405
406406 The fs argument must be a collection of Futures.
407407 """
@@ -747,7 +747,7 @@ def timeout(timeout, *, loop=None):
747747 ... yield from coro()
748748
749749
750- timeout: timeout value in seconds
750+ timeout: timeout value in seconds or None to disable timeout logic
751751 loop: asyncio compatible event loop
752752 """
753753 if loop is None :
@@ -768,17 +768,19 @@ def __enter__(self):
768768 if self ._task is None :
769769 raise RuntimeError ('Timeout context manager should be used '
770770 'inside a task' )
771- self ._cancel_handler = self ._loop .call_later (
772- self ._timeout , self ._cancel_task )
771+ if self ._timeout is not None :
772+ self ._cancel_handler = self ._loop .call_later (
773+ self ._timeout , self ._cancel_task )
773774 return self
774775
775776 def __exit__ (self , exc_type , exc_val , exc_tb ):
776777 if exc_type is futures .CancelledError and self ._cancelled :
777778 self ._cancel_handler = None
778779 self ._task = None
779780 raise futures .TimeoutError
780- self ._cancel_handler .cancel ()
781- self ._cancel_handler = None
781+ if self ._timeout is not None :
782+ self ._cancel_handler .cancel ()
783+ self ._cancel_handler = None
782784 self ._task = None
783785
784786 def _cancel_task (self ):
0 commit comments