2929from temporalio .api .enums .v1 import WorkflowTaskFailedCause
3030from temporalio .bridge .worker import PollShutdownError
3131from temporalio .converter import StorageDriverStoreContext , StorageDriverWorkflowInfo
32+ from temporalio .worker .workflow_sandbox ._runner import SandboxedWorkflowRunner
3233
3334from . import _command_aware_visitor
3435from ._interceptor import (
@@ -85,6 +86,9 @@ def __init__(
8586 encode_headers : bool ,
8687 max_workflow_task_external_storage_concurrency : int ,
8788 ) -> None :
89+ # Debug mode is enabled if specified or if the TEMPORAL_DEBUG env var is truthy
90+ debug_mode = debug_mode or bool (os .environ .get ("TEMPORAL_DEBUG" ))
91+
8892 self ._bridge_worker = bridge_worker
8993 self ._namespace = namespace
9094 self ._task_queue = task_queue
@@ -96,7 +100,19 @@ def __init__(
96100 )
97101 )
98102 self ._workflow_task_executor_user_provided = workflow_task_executor is not None
103+
104+ # If debug mode is enabled, ensure that the debugpy (https://github.com/microsoft/debugpy)
105+ # import is added as a passthrough
106+ if debug_mode and isinstance (workflow_runner , SandboxedWorkflowRunner ):
107+ workflow_runner = dataclasses .replace (
108+ workflow_runner ,
109+ restrictions = workflow_runner .restrictions .with_passthrough_modules (
110+ "_pydevd_bundle"
111+ ),
112+ )
113+
99114 self ._workflow_runner = workflow_runner
115+
100116 self ._unsandboxed_workflow_runner = unsandboxed_workflow_runner
101117 self ._data_converter = data_converter
102118 # Build the interceptor classes and collect extern functions
@@ -127,11 +143,9 @@ def __init__(
127143 )
128144 self ._throw_after_activation : Exception | None = None
129145
130- # If there's a debug mode or a truthy TEMPORAL_DEBUG env var, disable
131- # deadlock detection, otherwise set to 2 seconds
132- self ._deadlock_timeout_seconds = (
133- None if debug_mode or os .environ .get ("TEMPORAL_DEBUG" ) else 2
134- )
146+ # If debug mode is enabled, disable deadlock detection
147+ # otherwise set to 2 seconds
148+ self ._deadlock_timeout_seconds = None if debug_mode else 2
135149
136150 # Keep track of workflows that could not be evicted
137151 self ._could_not_evict_count = 0
0 commit comments