@@ -97,19 +97,17 @@ impl<T> AnyhowIntoPyResult<T> for anyhow::Result<T> {
9797#[ pyfunction]
9898fn init ( py : Python < ' _ > , settings : Pythonized < Settings > ) -> PyResult < ( ) > {
9999 py. allow_threads ( || -> anyhow:: Result < ( ) > {
100- init_lib_context ( settings. into_inner ( ) ) ?;
101- Ok ( ( ) )
100+ get_runtime ( ) . block_on ( async move { init_lib_context ( settings. into_inner ( ) ) . await } )
102101 } )
103102 . into_py_result ( )
104103}
105104
106105#[ pyfunction]
107106fn start_server ( py : Python < ' _ > , settings : Pythonized < ServerSettings > ) -> PyResult < ( ) > {
108107 py. allow_threads ( || -> anyhow:: Result < ( ) > {
109- let server = get_runtime ( ) . block_on ( server:: init_server (
110- get_lib_context ( ) ?,
111- settings. into_inner ( ) ,
112- ) ) ?;
108+ let server = get_runtime ( ) . block_on ( async move {
109+ server:: init_server ( get_lib_context ( ) . await ?, settings. into_inner ( ) ) . await
110+ } ) ?;
113111 get_runtime ( ) . spawn ( server) ;
114112 Ok ( ( ) )
115113 } )
@@ -202,7 +200,7 @@ impl FlowLiveUpdater {
202200 ) -> PyResult < Bound < ' py , PyAny > > {
203201 let flow = flow. 0 . clone ( ) ;
204202 future_into_py ( py, async move {
205- let lib_context = get_lib_context ( ) . into_py_result ( ) ?;
203+ let lib_context = get_lib_context ( ) . await . into_py_result ( ) ?;
206204 let live_updater = execution:: FlowLiveUpdater :: start (
207205 flow,
208206 lib_context. require_builtin_db_pool ( ) . into_py_result ( ) ?,
@@ -262,7 +260,7 @@ impl Flow {
262260 get_runtime ( )
263261 . block_on ( async {
264262 let exec_plan = self . 0 . flow . get_execution_plan ( ) . await ?;
265- let lib_context = get_lib_context ( ) ?;
263+ let lib_context = get_lib_context ( ) . await ?;
266264 let execution_ctx = self . 0 . use_execution_ctx ( ) . await ?;
267265 execution:: dumper:: evaluate_and_dump (
268266 & exec_plan,
@@ -457,9 +455,9 @@ pub struct SetupChangeBundle(Arc<setup::SetupChangeBundle>);
457455#[ pymethods]
458456impl SetupChangeBundle {
459457 pub fn describe_async < ' py > ( & self , py : Python < ' py > ) -> PyResult < Bound < ' py , PyAny > > {
460- let lib_context = get_lib_context ( ) . into_py_result ( ) ?;
461458 let bundle = self . 0 . clone ( ) ;
462459 future_into_py ( py, async move {
460+ let lib_context = get_lib_context ( ) . await . into_py_result ( ) ?;
463461 bundle. describe ( & lib_context) . await . into_py_result ( )
464462 } )
465463 }
@@ -469,10 +467,10 @@ impl SetupChangeBundle {
469467 py : Python < ' py > ,
470468 report_to_stdout : bool ,
471469 ) -> PyResult < Bound < ' py , PyAny > > {
472- let lib_context = get_lib_context ( ) . into_py_result ( ) ?;
473470 let bundle = self . 0 . clone ( ) ;
474471
475472 future_into_py ( py, async move {
473+ let lib_context = get_lib_context ( ) . await . into_py_result ( ) ?;
476474 let mut stdout = None ;
477475 let mut sink = None ;
478476 bundle
@@ -493,7 +491,7 @@ impl SetupChangeBundle {
493491#[ pyfunction]
494492fn flow_names_with_setup_async ( py : Python < ' _ > ) -> PyResult < Bound < ' _ , PyAny > > {
495493 future_into_py ( py, async move {
496- let lib_context = get_lib_context ( ) . into_py_result ( ) ?;
494+ let lib_context = get_lib_context ( ) . await . into_py_result ( ) ?;
497495 let setup_ctx = lib_context
498496 . require_persistence_ctx ( )
499497 . into_py_result ( ) ?
@@ -524,11 +522,15 @@ fn make_drop_bundle(flow_names: Vec<String>) -> PyResult<SetupChangeBundle> {
524522}
525523
526524#[ pyfunction]
527- fn remove_flow_context ( flow_name : String ) {
528- let lib_context_locked = crate :: lib_context:: LIB_CONTEXT . read ( ) . unwrap ( ) ;
529- if let Some ( lib_context) = lib_context_locked. as_ref ( ) {
530- lib_context. remove_flow_context ( & flow_name)
531- }
525+ fn remove_flow_context ( py : Python < ' _ > , flow_name : String ) -> PyResult < ( ) > {
526+ py. allow_threads ( || -> anyhow:: Result < ( ) > {
527+ get_runtime ( ) . block_on ( async move {
528+ let lib_context = get_lib_context ( ) . await . into_py_result ( ) ?;
529+ lib_context. remove_flow_context ( & flow_name) ;
530+ Ok ( ( ) )
531+ } )
532+ } )
533+ . into_py_result ( )
532534}
533535
534536#[ pyfunction]
0 commit comments