Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to pass None as a timeout value to disable timeout logic #834

Merged
merged 2 commits into from
Mar 21, 2016
Merged

Allow to pass None as a timeout value to disable timeout logic #834

merged 2 commits into from
Mar 21, 2016

Conversation

alexkey
Copy link
Contributor

@alexkey alexkey commented Mar 19, 2016

What these changes does?

Allows to pass None as a timeout value to disable timeout logic.

In some cases there is needed to disable timeout logic but keep it in convenient code structure without ugly if-branching like this:

if delay:
    with aiohttp.Timeout(delay):
        async with session.get(url) as response:
            pass  # ...
else:
    async with session.get(url) as response:
        pass  # ...

Now it is able to use the same code for both numerical and None timeout values:

for delay in [None, 0, 0.1, 1]:
    with aiohttp.Timeout(delay):
        async with session.get(url) as response:
            pass  # ...

This behaviour is similar to asyncio.wait_for(fut, timeout, *, loop=None) coroutine, which takes None as a timeout value to block until the future completes.

How to test your changes?

There is a test in test_timeout.py: test_timeout_disable.

Related issue number

None.

Checklist

  • Code is written and well
  • Tests for the changes are provided
  • Documentation reflects the changes

In some cases there is needed to disable timeout logic but keep it in
convenient code structure without ugly if-branching.
@coveralls
Copy link

Coverage Status

Coverage increased (+0.0006%) to 98.264% when pulling 06e0e52 on alexkey:disable_timeout_with_none into a1f39a9 on KeepSafe:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.0006%) to 98.264% when pulling 6b61832 on alexkey:disable_timeout_with_none into a1f39a9 on KeepSafe:master.

asvetlov added a commit that referenced this pull request Mar 21, 2016
Allow to pass None as a timeout value to disable timeout logic
@asvetlov asvetlov merged commit 1444178 into aio-libs:master Mar 21, 2016
@asvetlov
Copy link
Member

Thanks!

@alexkey alexkey deleted the disable_timeout_with_none branch March 22, 2016 07:55
@alexkey alexkey restored the disable_timeout_with_none branch March 22, 2016 10:58
@alexkey alexkey deleted the disable_timeout_with_none branch March 22, 2016 11:03
@lock
Copy link

lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants