diff --git a/wheel/src/run_generator.rs b/wheel/src/run_generator.rs index bc364728b..00be27e35 100644 --- a/wheel/src/run_generator.rs +++ b/wheel/src/run_generator.rs @@ -20,7 +20,7 @@ pub fn py_to_slice<'a>(buf: PyBuffer) -> &'a [u8] { #[pyfunction] pub fn run_block_generator<'a>( - _py: Python<'a>, + py: Python<'a>, program: PyBuffer, block_refs: &Bound<'_, PyList>, max_cost: Cost, @@ -29,12 +29,15 @@ pub fn run_block_generator<'a>( ) -> (Option, Option) { let mut allocator = make_allocator(flags); - let refs = block_refs.into_iter().map(|b| { - let buf = b - .extract::>() - .expect("block_refs should be a list of buffers"); - py_to_slice::<'a>(buf) - }); + let refs = block_refs + .into_iter() + .map(|b| { + let buf = b + .extract::>() + .expect("block_refs should be a list of buffers"); + py_to_slice::<'a>(buf) + }) + .collect::>(); let program = py_to_slice::<'a>(program); let run_block = if (flags & ANALYZE_SPENDS) == 0 { native_run_block_generator::<_, EmptyVisitor, _> @@ -42,24 +45,26 @@ pub fn run_block_generator<'a>( native_run_block_generator::<_, MempoolVisitor, _> }; - match run_block(&mut allocator, program, refs, max_cost, flags, constants) { - Ok(spend_bundle_conds) => ( - None, - Some(OwnedSpendBundleConditions::from( - &allocator, - spend_bundle_conds, - )), - ), - Err(ValidationErr(_, error_code)) => { - // a validation error occurred - (Some(error_code.into()), None) + py.allow_threads(|| { + match run_block(&mut allocator, program, refs, max_cost, flags, constants) { + Ok(spend_bundle_conds) => ( + None, + Some(OwnedSpendBundleConditions::from( + &allocator, + spend_bundle_conds, + )), + ), + Err(ValidationErr(_, error_code)) => { + // a validation error occurred + (Some(error_code.into()), None) + } } - } + }) } #[pyfunction] pub fn run_block_generator2<'a>( - _py: Python<'a>, + py: Python<'a>, program: PyBuffer, block_refs: &Bound<'_, PyList>, max_cost: Cost, @@ -68,12 +73,15 @@ pub fn run_block_generator2<'a>( ) -> (Option, Option) { let mut allocator = make_allocator(flags); - let refs = block_refs.into_iter().map(|b| { - let buf = b - .extract::>() - .expect("block_refs must be list of buffers"); - py_to_slice::<'a>(buf) - }); + let refs = block_refs + .into_iter() + .map(|b| { + let buf = b + .extract::>() + .expect("block_refs must be list of buffers"); + py_to_slice::<'a>(buf) + }) + .collect::>(); let program = py_to_slice::<'a>(program); let run_block = if (flags & ANALYZE_SPENDS) == 0 { @@ -82,17 +90,19 @@ pub fn run_block_generator2<'a>( native_run_block_generator2::<_, MempoolVisitor, _> }; - match run_block(&mut allocator, program, refs, max_cost, flags, constants) { - Ok(spend_bundle_conds) => ( - None, - Some(OwnedSpendBundleConditions::from( - &allocator, - spend_bundle_conds, - )), - ), - Err(ValidationErr(_, error_code)) => { - // a validation error occurred - (Some(error_code.into()), None) + py.allow_threads(|| { + match run_block(&mut allocator, program, refs, max_cost, flags, constants) { + Ok(spend_bundle_conds) => ( + None, + Some(OwnedSpendBundleConditions::from( + &allocator, + spend_bundle_conds, + )), + ), + Err(ValidationErr(_, error_code)) => { + // a validation error occurred + (Some(error_code.into()), None) + } } - } + }) }