Skip to main content

Like atexit, but for asyncio

Project description

asyncio atexit

Adds atexit functionality to asyncio:

import asyncio_atexit

async def close_db():
    await db_connection.close()

asyncio_atexit.register(close_db)

atexit is part of the standard library, and gives you a way to register functions to call when the interpreter exits.

asyncio doesn't have equivalent functionality to register functions when the event loop exits:

This package adds functionality that can be considered equivalent to atexit.register, but tied to the event loop lifecycle. It:

  1. accepts both coroutines and synchronous functions
  2. should be called from a running event loop
  3. calls registered cleanup functions when the event loop closes
  4. only works if the application running the event loop calls close()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asyncio-atexit-1.0.1.tar.gz (4.4 kB view hashes)

Uploaded Source

Built Distribution

asyncio_atexit-1.0.1-py3-none-any.whl (3.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page