@@ -42,17 +42,17 @@ use pyo3::exceptions::PyValueError;
4242use pyo3:: prelude:: * ;
4343use pyo3:: pybacked:: PyBackedStr ;
4444use pyo3:: types:: { PyCapsule , PyList , PyTuple , PyTupleMethods } ;
45- use tokio:: { runtime:: Handle , task :: JoinHandle } ;
45+ use tokio:: runtime:: Handle ;
4646
4747use crate :: catalog:: PyTable ;
48- use crate :: errors:: { py_datafusion_err, to_datafusion_err , PyDataFusionError } ;
48+ use crate :: errors:: { py_datafusion_err, PyDataFusionError } ;
4949use crate :: expr:: sort_expr:: to_sort_expressions;
5050use crate :: physical_plan:: PyExecutionPlan ;
5151use crate :: record_batch:: PyRecordBatchStream ;
5252use crate :: sql:: logical:: PyLogicalPlan ;
5353use crate :: utils:: {
54- get_tokio_runtime, is_ipython_env, py_obj_to_scalar_value, spawn_stream, validate_pycapsule ,
55- wait_for_future,
54+ get_tokio_runtime, is_ipython_env, py_obj_to_scalar_value, spawn_stream, spawn_streams ,
55+ validate_pycapsule , wait_for_future,
5656} ;
5757use crate :: {
5858 errors:: PyDataFusionResult ,
@@ -960,16 +960,9 @@ impl PyDataFrame {
960960 }
961961
962962 fn execute_stream_partitioned ( & self , py : Python ) -> PyResult < Vec < PyRecordBatchStream > > {
963- // create a Tokio runtime to run the async code
964- let rt = & get_tokio_runtime ( ) . 0 ;
965963 let df = self . df . as_ref ( ) . clone ( ) ;
966- let fut: JoinHandle < datafusion:: common:: Result < Vec < SendableRecordBatchStream > > > =
967- rt. spawn ( async move { df. execute_stream_partitioned ( ) . await } ) ;
968- let stream = wait_for_future ( py, async { fut. await . map_err ( to_datafusion_err) } ) ?
969- . map_err ( py_datafusion_err) ?
970- . map_err ( py_datafusion_err) ?;
971-
972- Ok ( stream. into_iter ( ) . map ( PyRecordBatchStream :: new) . collect ( ) )
964+ let streams = spawn_streams ( py, async move { df. execute_stream_partitioned ( ) . await } ) ?;
965+ Ok ( streams. into_iter ( ) . map ( PyRecordBatchStream :: new) . collect ( ) )
973966 }
974967
975968 /// Convert to pandas dataframe with pyarrow
0 commit comments