Skip to content
This repository has been archived by the owner on Aug 5, 2023. It is now read-only.

Support aenter/aexit #4

Merged
merged 1 commit into from
Feb 28, 2018
Merged

Conversation

steersbob
Copy link
Contributor

Defect

The following code would fail to await the aiohttp.ClientSession.close() coroutine, or attempt to close the session after the event loop closed.

with AsyncInfluxDBClient(mode='async') as client:
    pass

Desired behavior

def blocking_func():
    with AsyncInfluxDBClient(mode='blocking') as client:
        pass

async def async_func():
    async with AsyncInfluxDBClient(mode='async') as client:
        pass

Changes

  • Added __aenter__, __aexit__, and close functions
  • Removed __del__ function. For well-handled cleanup, clients can either explicitly close, or use the context guard. This also avoids unwanted side effects where __del__ is called after the event loop closes.
  • async_client fixture is now async, and uses a module scoped event loop

@gusutabopb
Copy link
Owner

Look quite solid!

Thank you!

@gusutabopb gusutabopb merged commit 3ef2e4a into gusutabopb:master Feb 28, 2018
@steersbob steersbob deleted the async-close-support branch February 28, 2018 11:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants