Skip to content

How to stop a task started using asyncio.start_server #9289

Discussion options

You must be logged in to vote

You can use close and wait_closed methods:

myserver.close()
await myserver.wait_closed()

Or async with, and when the with finishes it'll automatically close the server. That allows you to wait on an event, eg:

async with myserver:
    await event.wait()
# myserver will be closed when you get here

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
7 replies
@krishnak
Comment options

@dpgeorge
Comment options

@krishnak
Comment options

@dpgeorge
Comment options

@krishnak
Comment options

Answer selected by krishnak
Comment options

You must be logged in to vote
1 reply
@krishnak
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants