mirror of
https://github.com/facebook/sapling.git
synced 2024-10-08 15:57:43 +03:00
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:
parent
74db74527e
commit
f8f149c2ac
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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())))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user