File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -642,7 +642,12 @@ def current() -> _Runtime:
642
642
643
643
@staticmethod
644
644
def maybe_current () -> Optional [_Runtime ]:
645
- return getattr (asyncio .get_running_loop (), "__temporal_workflow_runtime" , None )
645
+ try :
646
+ return getattr (
647
+ asyncio .get_running_loop (), "__temporal_workflow_runtime" , None
648
+ )
649
+ except RuntimeError :
650
+ return None
646
651
647
652
@staticmethod
648
653
def set_on_loop (
Original file line number Diff line number Diff line change @@ -7975,6 +7975,37 @@ async def test_quick_activity_swallows_cancellation(client: Client):
7975
7975
temporalio .worker ._workflow_instance ._raise_on_cancelling_completed_activity_override = False
7976
7976
7977
7977
7978
+ @activity .defn
7979
+ def use_in_workflow () -> bool :
7980
+ return workflow .in_workflow ()
7981
+
7982
+
7983
+ @workflow .defn
7984
+ class UseInWorkflow :
7985
+ @workflow .run
7986
+ async def run (self ):
7987
+ res = await workflow .execute_activity (
7988
+ use_in_workflow , schedule_to_close_timeout = timedelta (seconds = 10 )
7989
+ )
7990
+ return res
7991
+
7992
+
7993
+ async def test_in_workflow_sync (client : Client ):
7994
+ async with new_worker (
7995
+ client ,
7996
+ UseInWorkflow ,
7997
+ activities = [use_in_workflow ],
7998
+ activity_executor = concurrent .futures .ThreadPoolExecutor (max_workers = 1 ),
7999
+ ) as worker :
8000
+ res = await client .execute_workflow (
8001
+ UseInWorkflow .run ,
8002
+ id = f"test_in_workflow_sync" ,
8003
+ task_queue = worker .task_queue ,
8004
+ execution_timeout = timedelta (minutes = 1 ),
8005
+ )
8006
+ assert not res
8007
+
8008
+
7978
8009
class SignalInterceptor (temporalio .worker .Interceptor ):
7979
8010
def workflow_interceptor_class (
7980
8011
self , input : temporalio .worker .WorkflowInterceptorClassInput
You can’t perform that action at this time.
0 commit comments