You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/develop/python/python-sdk-sync-vs-async.mdx
+10-9Lines changed: 10 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -71,37 +71,38 @@ such as `aiohttp` or `httpx`. Otherwise, use a synchronous Activity.
71
71
72
72
Python workers have following components for executing code:
73
73
74
-
- Your event loop, which runs tasks from async activities **plus the rest of Temporal, such as communicating with the server**.
74
+
- Your event loop, which runs tasks from async activities **plus the rest of the Temporal Worker, such as communicating with the server**.
75
75
- An executor for executing activity tasks from synchronous activities. A thread pool executor is recommended.
76
-
- A thread pool executor for executing workflow tasks (see forum post [here](https://community.temporal.io/t/whats-the-workflow-task-executor-in-the-python-worker-configuration/16965)).
76
+
- A thread pool executor for executing workflow tasks.
77
77
78
78
> See Also: [docs for](https://python.temporal.io/temporalio.worker.Worker.html#__init__)`worker.__init__()`
79
79
80
80
### Activities
81
81
82
-
- The activities and the temporal worker SDK code both run in whatever event loop the user gives the worker (which is often the default asyncio event loop).
82
+
- The activities and the temporal worker SDK code both run the default asyncio event loop or whatever event loop you give the Worker.
83
83
- Synchronous Activities run in the `activity_executor`.
84
84
85
85
### Workflows
86
86
87
87
Since workflow tasks (1) are CPU bound, (2) need to be timed out for deadlock detection, and (3) need to not block other workflow tasks, they are run in threads. The `workflow_task_executor` is the thread pool these tasks are run on.
88
88
89
-
This can be confusing at first because Workflow Definitions are `async`, but this `async` is not referring to the standard event loop -- it is referring to the workflow's own SDK event loop.
89
+
The fact that Workflow Tasks run in a thread pool can be confusing at first because Workflow Definitions are `async`.
90
+
The key differentiator is that the `async` in Workflow Definitions is not referring to the standard event loop -- it is referring to the workflow's own event loop.
90
91
Each workflow gets its own “workflow event loop”, which is deterministic, and described in [the Python SDK blog](https://temporal.io/blog/durable-distributed-asyncio-event-loop#temporal-workflows-are-asyncio-event-loops).
91
-
The workflow event loop doesn't constantly loop – it just gets cycled through during a workflow task to make as much progress as possible on any all of its futures.
92
+
The workflow event loop doesn't constantly loop -- it just gets cycled through during a workflow task to make as much progress as possible on all of its futures.
92
93
When it can no longer make progress on any of its futures, then the Workflow Task is complete.
93
94
94
-
### Number of cores
95
+
### Number of CPU cores
95
96
96
-
The only ways to use more than one CPU core in a python worker (considering the GIL) are:
97
+
The only ways to use more than one core in a python worker (considering Python's GIL) are:
97
98
98
-
- Run the sync activities in a process pool executor, but a thread pool executor is recommended.
99
99
- Run more than one worker process.
100
+
- Run the sync activities in a process pool executor, but a thread pool executor is recommended.
100
101
101
102
### Separating Activity and Workflow Workers
102
103
103
104
To reduce the risk of event loops or executors getting blocked,
104
-
some users choose to deploy separate workers for workflow tasks and activity tasks.
105
+
some users choose to deploy separate Workers for Workflow Tasks and Activity Tasks.
0 commit comments