@@ -113,6 +113,12 @@ where
113
113
Ok ( ( ) )
114
114
}
115
115
116
+ fn cancelled ( future : & PyAny ) -> PyResult < bool > {
117
+ future. getattr ( "cancelled" ) ?
118
+ . call0 ( ) ?
119
+ . is_true ( )
120
+ }
121
+
116
122
fn set_result ( py : Python , future : & PyAny , result : PyResult < PyObject > ) -> PyResult < ( ) > {
117
123
match result {
118
124
Ok ( val) => {
@@ -214,29 +220,32 @@ where
214
220
let result = fut. await ;
215
221
216
222
Python :: with_gil ( move |py| {
217
- if set_result ( py , future_tx1. as_ref ( py) , result )
223
+ if cancelled ( future_tx1. as_ref ( py) )
218
224
. map_err ( dump_err ( py) )
219
- . is_err ( )
220
- {
221
-
222
- // Cancelled
225
+ . unwrap_or ( false ) {
226
+ return ;
223
227
}
228
+
229
+ let _ = set_result ( py, future_tx1. as_ref ( py) , result)
230
+ . map_err ( dump_err ( py) ) ;
224
231
} ) ;
225
232
} )
226
233
. await
227
234
{
228
235
if e. is_panic ( ) {
229
236
Python :: with_gil ( move |py| {
230
- if set_result (
237
+ if cancelled ( future_tx2. as_ref ( py) )
238
+ . map_err ( dump_err ( py) )
239
+ . unwrap_or ( false ) {
240
+ return ;
241
+ }
242
+
243
+ let _ = set_result (
231
244
py,
232
245
future_tx2. as_ref ( py) ,
233
246
Err ( PyException :: new_err ( "rust future panicked" ) ) ,
234
247
)
235
- . map_err ( dump_err ( py) )
236
- . is_err ( )
237
- {
238
- // Cancelled
239
- }
248
+ . map_err ( dump_err ( py) ) ;
240
249
} ) ;
241
250
}
242
251
}
@@ -332,29 +341,32 @@ where
332
341
let result = fut. await ;
333
342
334
343
Python :: with_gil ( move |py| {
335
- if set_result ( py , future_tx1. as_ref ( py) , result )
344
+ if cancelled ( future_tx1. as_ref ( py) )
336
345
. map_err ( dump_err ( py) )
337
- . is_err ( )
338
- {
339
-
340
- // Cancelled
346
+ . unwrap_or ( false ) {
347
+ return ;
341
348
}
349
+
350
+ let _ = set_result ( py, future_tx1. as_ref ( py) , result)
351
+ . map_err ( dump_err ( py) ) ;
342
352
} ) ;
343
353
} )
344
354
. await
345
355
{
346
356
if e. is_panic ( ) {
347
357
Python :: with_gil ( move |py| {
348
- if set_result (
358
+ if cancelled ( future_tx2. as_ref ( py) )
359
+ . map_err ( dump_err ( py) )
360
+ . unwrap_or ( false ) {
361
+ return ;
362
+ }
363
+
364
+ let _ = set_result (
349
365
py,
350
366
future_tx2. as_ref ( py) ,
351
367
Err ( PyException :: new_err ( "rust future panicked" ) ) ,
352
368
)
353
- . map_err ( dump_err ( py) )
354
- . is_err ( )
355
- {
356
- // Cancelled
357
- }
369
+ . map_err ( dump_err ( py) ) ;
358
370
} ) ;
359
371
}
360
372
}
0 commit comments