Skip to content

asleep-cult/asygpy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

asygpy

asyncio signal handlers for Windows and Unix.

Reveiving Signals

import asygpy
import asyncio
import signal

async def main() -> None:
    notifier = asygpy.create_notifier()
    channel = (
        notifier.open_channel()
        .add_signal(signal.SIGINT)
        .add_signal(signal.SIGTERM)
    )
    notifier.start_notifying()

    signum = await channel.receive()
    if signum == signal.SIGINT:
        print("Shutting down due to SIGINT")
    elif signum == signal.SIGTERM:
        print("Shutting down due to SIGTERM")

    notifier.stop_notifying()

asyncio.run(main())

Receiving Multiple Signals

import asygpy
import asyncio
import signal

async def main() -> None:
    notifier = asygpy.create_notifier()
    channel = (
        notifier.open_channel()
        .add_signal(signal.SIGINT)
        .add_signal(signal.SIGTERM)
    )
    notifier.start_notifying()

    async for signum in channel:
        if signum == signal.SIGINT:
            print("I received SIGINT but I don't care!")
        elif signum == signal.SIGTERM:
            print("I received SIGTERM but I don't care!")

asyncio.run(main())

About

asyncio signal handlers for Windows and Unix

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages