diff --git a/telethon/client/updates.py b/telethon/client/updates.py index a789e77c..db5e3f3d 100644 --- a/telethon/client/updates.py +++ b/telethon/client/updates.py @@ -393,7 +393,11 @@ class UpdateMethods: # inserted because this is a rather expensive operation # (default's sqlite3 takes ~0.1s to commit changes). Do # it every minute instead. No-op if there's nothing new. - await self.session.save() + try: + await self.session.save() + except OSError as e: + # No big deal if this cannot be immediately saved + self._log[__name__].warning('Could not perform the periodic save of session data: %s: %s', type(e), e) async def _dispatch_update(self: 'TelegramClient', update): # TODO only used for AlbumHack, and MessageBox is not really designed for this diff --git a/telethon/client/users.py b/telethon/client/users.py index 615d97cf..4436cbbd 100644 --- a/telethon/client/users.py +++ b/telethon/client/users.py @@ -71,7 +71,11 @@ class UserMethods: exceptions.append(e) results.append(None) continue - await self.session.process_entities(result) + try: + await self.session.process_entities(result) + except OSError: + self._log[__name__].warning( + 'Failed to save possibly new entities to the session: %s: %s', type(e), e) self._entity_cache.add(result) exceptions.append(None) results.append(result) @@ -82,7 +86,14 @@ class UserMethods: return results else: result = await future - await self.session.process_entities(result) + # This is called pretty often, and it's okay if it fails every now and then. + # It only means certain entities won't be saved. + try: + await self.session.process_entities(result) + except OSError: + self._log[__name__].warning( + 'Failed to save possibly new entities to the session: %s: %s', type(e), e) + self._entity_cache.add(result) return result except (errors.ServerError, errors.RpcCallFailError,