Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[QUESTION] Stop bot with infinite background job/task gracefully #3184

Closed Answered by max-dw-i
max-dw-i asked this question in Q&A
Discussion options

You must be logged in to vote

I got notified that this topic is still alive :) For anyone who might stumble upon this question, that's what we use at the moment (main parts):

class QueueConsumer:
    def __init__(self, bot, ...):
        self.bot = bot
        self.connection = None
        self.consumer_lock = None

    async def process_message(self, msg):
        await self.bot.send_message(msg)

    async def run_consumer(self):
        self.connection = await subscribe(on_message=self.process_message, ...)
        self.consumer_lock = asyncio.Future()
        await self.consumer_lock

    async def signal_handler(self):
        if self.connection is not None:
            await self.connection.close()
            if 

Replies: 4 comments 1 reply

Comment options

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

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by max-dw-i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
3 participants
Converted from issue

This discussion was converted from issue #3181 on August 04, 2022 15:37.