pydag: make async function interruptible

Summary:
Use the interruptible block_on API so the Python methods can be interrupted by Ctrl+C.
This is especially useful if some operation triggers lots of expensive network fetches.

Reviewed By: DurhamG

Differential Revision: D28723008

fbshipit-source-id: b6c692de6290a49852eabcd960ebd9b2fb68685a
This commit is contained in:
Jun Wu 2021-05-26 18:59:06 -07:00 committed by Facebook GitHub Bot
parent 74db74527e
commit f8f149c2ac
4 changed files with 5 additions and 5 deletions

View File

@ -10,7 +10,7 @@ use crate::idmap;
use crate::Names;
use crate::Spans;
use anyhow::Result;
use async_runtime::block_on_exclusive as block_on;
use async_runtime::try_block_unless_interrupted as block_on;
use cpython::*;
use cpython_ext::convert::BytesLike;
use cpython_ext::ExtractInner;

View File

@ -6,7 +6,7 @@
*/
use crate::Names;
use async_runtime::block_on_exclusive as block_on;
use async_runtime::try_block_unless_interrupted as block_on;
use cpython::*;
use cpython_ext::ResultPyErrExt;
use cpython_ext::Str;

View File

@ -5,7 +5,7 @@
* GNU General Public License version 2.
*/
use async_runtime::block_on_exclusive as block_on;
use async_runtime::try_block_unless_interrupted as block_on;
use cpython::*;
use cpython_ext::ResultPyErrExt;
use dag::ops::IdConvert;

View File

@ -8,7 +8,7 @@
use crate::dagalgo::dagalgo;
use crate::idmap::NULL_NODE;
use anyhow::Result;
use async_runtime::block_on_exclusive as block_on;
use async_runtime::try_block_unless_interrupted as block_on;
use cpython::*;
use cpython_ext::{AnyhowResultExt, ResultPyErrExt};
use dag::nameset::hints::Flags;
@ -169,7 +169,7 @@ py_class!(pub class nameiter |py| {
def __next__(&self) -> PyResult<Option<PyBytes>> {
let mut iter = self.iter(py).borrow_mut();
let next: Option<Vertex> = block_on(iter.next()).transpose().map_pyerr(py)?;
let next: Option<Vertex> = block_on(async { iter.next().await.transpose() }).map_pyerr(py)?;
Ok(next.map(|name| PyBytes::new(py, name.as_ref())))
}