eternnoir / pyTelegramBotAPI

Python Telegram bot api.
GNU General Public License v2.0
8.11k stars 2.03k forks source link

RedisHandlerBackend and FileHandlerBackend lead to error "cannot pickle '_thread.lock' object" #2342

Closed fuse98 closed 3 months ago

fuse98 commented 4 months ago

pyTelegramBotAPI version: 4.16.1 OS version: Ubuntu 22.04.4 LTS Python version: 3.10.12

Hi

I have a simple bot that runs on pulling mode with the default number of threads(which is 2). I was looking for a more solid way to register my next_step_handlers and I stumbled upon RedisHandlerBackend and FileHandlerBackend.

I tried them both. by setting the next_step_backend when instantiating the bot. they both gave this error: TypeError: cannot pickle '_thread.lock' object

here is the complete stack:

2024-07-09 15:50:36,546 (init.py:1021 MainThread) ERROR - TeleBot: "Infinity polling exception: cannot pickle '_thread.lock' object" 2024-07-09 15:50:36,547 (init.py:1023 MainThread) ERROR - TeleBot: "Exception traceback: Traceback (most recent call last): File "/home/moein/Dev/carryBuddy/telbot/venv/lib/python3.10/site-packages/telebot/init.py", line 1016, in infinity_polling self.polling(non_stop=True, timeout=timeout, long_polling_timeout=long_polling_timeout, File "/home/moein/Dev/carryBuddy/telbot/venv/lib/python3.10/site-packages/telebot/init.py", line 1104, in polling self.threaded_polling(non_stop=non_stop, interval=interval, timeout=timeout, long_polling_timeout=long_polling_timeout, File "/home/moein/Dev/carryBuddy/telbot/venv/lib/python3.10/site-packages/telebot/init.py", line 1179, in __threaded_polling raise e File "/home/moein/Dev/carryBuddy/telbot/venv/lib/python3.10/site-packages/telebot/init.py", line 1141, in threaded_polling self.worker_pool.raise_exceptions() File "/home/moein/Dev/carryBuddy/telbot/venv/lib/python3.10/site-packages/telebot/util.py", line 149, in raise_exceptions raise self.exception_info File "/home/moein/Dev/carryBuddy/telbot/venv/lib/python3.10/site-packages/telebot/util.py", line 92, in run task(*args, kwargs) File "/home/moein/Dev/carryBuddy/telbot/venv/lib/python3.10/site-packages/telebot/init.py", line 7866, in _run_middlewares_and_handler result = handler['function'](message, bot=self) File "/home/moein/Dev/carryBuddy/telbot/src/carrybot/message_handlers/new_travel.py", line 172, in handel_edit_description bot.register_next_step_handler(msg, NewTravelController.handel_submit_description, bot, msg_id) File "/home/moein/Dev/carryBuddy/telbot/venv/lib/python3.10/site-packages/telebot/init.py", line 6127, in register_next_step_handler self.register_next_step_handler_by_chat_id(message.chat.id, callback, *args, *kwargs) File "/home/moein/Dev/carryBuddy/telbot/venv/lib/python3.10/site-packages/telebot/init.py", line 6288, in register_next_step_handler_by_chat_id self.next_step_backend.register_handler(chat_id, Handler(callback, args, kwargs)) File "/home/moein/Dev/carryBuddy/telbot/venv/lib/python3.10/site-packages/telebot/handler_backends.py", line 149, in register_handler

coder2020official commented 4 months ago

Switch to states

coder2020official commented 4 months ago

I can't really investigate this issue. Check your code with examples and see if you are doing something wrong.

fuse98 commented 3 months ago

Sorry for the delay In response. I figured out that the problem was passing the "bot" object was the issue. It seems that Telebot object is not serializable.