Closed
Description
Steps to reproduce
- Set the
working
variable toFalse
- Run the bot using
./main.py
- Hit ctrl + c
Expected behaviour
The bot should stop.
Actual behaviour
The bot hangs.
Configuration
Operating System: 10.15.5 (19F101)
Version of Python, python-telegram-bot & dependencies:
python-telegram-bot 12.8
certifi 2020.06.20
Python 3.7.7 (default, Mar 10 2020, 15:43:33) [Clang 11.0.0 (clang-1100.0.33.17)]
Logs
Working:
> ./main.py
2020-07-02 12:59:25,880 - __main__ - INFO - Started polling
2020-07-02 12:59:26,157 - __main__ - INFO - Bot started. Press Ctrl-C to stop.
^C2020-07-02 12:59:27,504 - telegram.ext.updater - INFO - Received signal 2 (SIGINT), stopping...
then exits.
Not working:
> ./main.py
2020-07-02 12:59:34,283 - telegram.ext.updater - WARNING - Connection pool of Request object is smaller than optimal value (8)
2020-07-02 12:59:34,283 - __main__ - INFO - Started polling
2020-07-02 12:59:34,537 - __main__ - INFO - Bot started. Press Ctrl-C to stop.
^C2020-07-02 12:59:37,574 - telegram.ext.updater - INFO - Received signal 2 (SIGINT), stopping...
and hangs.
main.py
:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
from telegram.ext import Updater
from queue_bot import QueueBot
logger = logging.getLogger(__name__)
updater = None
def main():
logger.info('Started polling')
updater.start_polling(timeout=0.01)
logger.info('Bot started. Press Ctrl-C to stop.')
updater.idle()
if __name__ == '__main__':
token = 'TOKEN'
working = True
if working:
updater = Updater(token, use_context=True)
else:
queue_bot = QueueBot(token)
updater = Updater(bot=queue_bot, use_context=True)
main()
queue_bot.py
:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from telegram.bot import Bot
from telegram.ext import messagequeue
class QueueBot(Bot):
def __init__(self, *args, **kwargs):
super(QueueBot, self).__init__(*args, **kwargs)
self._is_messages_queued_default = True
self._msg_queue = messagequeue.MessageQueue()
def __del__(self):
try:
self._msg_queue.stop()
except:
pass
@messagequeue.queuedmessage
def send_message(self, *args, **kwargs):
return super(QueueBot, self).send_message(*args, **kwargs)
Metadata
Metadata
Assignees
Labels
No labels