File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -234,12 +234,14 @@ async def _maybe_save_document(self, saving_document: asyncio.Task | None) -> No
234
234
if saving_document is not None and not saving_document .done ():
235
235
# the document is being saved, cancel that
236
236
saving_document .cancel ()
237
- await saving_document
238
237
239
- # save after X seconds of inactivity
240
- await asyncio . sleep ( self . _save_delay )
238
+ # all async code (i.e. await statements) must be part of this try/except block
239
+ # because this coroutine is run in a cancellable task and cancellation is handled here
241
240
242
241
try :
242
+ # save after X seconds of inactivity
243
+ await asyncio .sleep (self ._save_delay )
244
+
243
245
self .log .info ("Saving the content from room %s" , self ._room_id )
244
246
await self ._file .maybe_save_content (
245
247
{
@@ -253,6 +255,9 @@ async def _maybe_save_document(self, saving_document: asyncio.Task | None) -> No
253
255
254
256
self ._emit (LogLevel .INFO , "save" , "Content saved." )
255
257
258
+ except asyncio .CancelledError :
259
+ return
260
+
256
261
except OutOfBandChanges :
257
262
self .log .info ("Out-of-band changes. Overwriting the content in room %s" , self ._room_id )
258
263
try :
You can’t perform that action at this time.
0 commit comments