Telethon: sqlite3.OperationalError: database is locked

Hello,

Running telethon client with multi workers under pool executor causes constant database locks:

ERROR:telethon.telegram_bare_client:Connection was reset while receiving items. Reconnecting ERROR:telethon.telegram_bare_client:Connection was reset while receiving items. Reconnecting ERROR:telethon.telegram_bare_client:Unknown exception in the read thread! Disconnecting and leaving it to main t Traceback (most recent call last): File "/usr/local/lib/python3.4/dist-packages/telethon/telegram_bare_client.py", line 690, in _recv_thread_impl self.idle(stop_signals=tuple()) File "/usr/local/lib/python3.4/dist-packages/telethon/telegram_bare_client.py", line 659, in idle self._sender.receive(update_state=self.updates) File "/usr/local/lib/python3.4/dist-packages/telethon/network/mtproto_sender.py", line 147, in receive self._process_msg(remote_msg_id, remote_seq, reader, update_state) File "/usr/local/lib/python3.4/dist-packages/telethon/network/mtproto_sender.py", line 197, in _process_msg return self._handle_rpc_result(msg_id, sequence, reader) File "/usr/local/lib/python3.4/dist-packages/telethon/network/mtproto_sender.py", line 496, in _handle_rpc_res self.session.process_entities(request.result) File "/usr/local/lib/python3.4/dist-packages/telethon/session.py", line 405, in process_entities 'insert or replace into entities values (?,?,?,?,?)', rows sqlite3.OperationalError: database is locked

Is there a way we can fix this?

Thank you, Andrei.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (7 by maintainers)

Commits related to this issue

Most upvoted comments

That’s not a problem related to the library, and you should ask somewhere else.

Well you should know if you have a connected client on a certain file.

Okay well the problem is that you’re using the same 'session' file from many TelegramClient’s at once. There should only be one TelegramClient running on a given 'session' file. So either you reuse the same client or you use multiple session filenames.

Disabling saving entities is generally not a good idea, since they are required for a lot of things. The library is not thread-safe. It’s designed to work well in asyncio, not with threads, and that probably wouldn’t solve the locked issue. I’m glad you like the library, though. But avoiding the issue is as simple as either using different session names or not running two scripts at once with the same file…

Is there a way we can fix this?

Is there any way I can reproduce this?