Skip to content

Commit 7ef2608

Browse files
committed
fixed most lints
1 parent ecbcd9d commit 7ef2608

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

docs/develop/python/python-sdk-sync-vs-async.mdx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,13 @@ Python workers have following components for executing code:
8484

8585
### Workflows
8686

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.
87+
Since Workflow Tasks have the following three properties, they're run in threads.
8888

89+
* are CPU bound
90+
* need to be timed out for deadlock detection
91+
* need to not block other Workflow Tasks
92+
93+
The `workflow_task_executor` is the thread pool these Tasks are run on.
8994
The fact that Workflow Tasks run in a thread pool can be confusing at first because Workflow Definitions are `async`.
9095
The key differentiator is that the `async` in Workflow Definitions isn't referring to the standard event loop -- it's referring to the Workflow's own event loop.
9196
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).
@@ -94,21 +99,21 @@ When it can no longer make progress on any of its futures, then the Workflow Tas
9499

95100
### Number of CPU cores
96101

97-
The only ways to use more than one core in a python worker (considering Python's GIL) are:
102+
The only ways to use more than one core in a python Worker (considering Python's GIL) are:
98103

99-
- Run more than one worker process.
104+
- Run more than one Worker Process.
100105
- Run the synchronous Activities in a process pool executor, but a thread pool executor is recommended.
101106

102-
### Separating Activity and Workflow Workers
107+
### A Worker infrastructure option: Separate Activity and Workflow Workers
103108

104109
To reduce the risk of event loops or executors getting blocked,
105110
some users choose to deploy separate Workers for Workflow Tasks and Activity Tasks.
106111

107112
## Activity Definition
108113

109114
**By default, Activities should be synchronous rather than asynchronous**.
110-
You should only make an Activity asynchronous if you are _very_
111-
sure that it does not block the event loop.
115+
You should only make an Activity asynchronous if you are
116+
certain that it doesn't block the event loop.
112117

113118
This is because if you have blocking code in an `async def` function,
114119
it blocks your event loop and the rest of Temporal, which can cause bugs that are
@@ -123,11 +128,10 @@ which helps because:
123128
- If you have multiple
124129
Activity Tasks running in a thread pool rather than an event loop, one bad
125130
Activity Task can't slow down the others; this is because the OS scheduler preemptively
126-
switches between threads, which the event loop coordinator does not do.
131+
switches between threads, which the event loop coordinator doesn't do.
127132

128133
> See Also:
129134
> ["Types of Activities" section of Python SDK README](https://github.com/temporalio/sdk-python#types-of-activities)
130-
> and [Sync vs Async activity implementations](https://docs.temporal.io/develop/python/python-sdk-sync-vs-async)
131135
132136
## How to implement Synchronous Activities
133137

@@ -162,7 +166,7 @@ class TranslateActivities:
162166

163167
The preceeding example doesn't share a session across the Activity, so
164168
`__init__` was removed. While `requests` does have the ability to create sessions,
165-
it's currently unknown if they are thread safe. Due to no longer having or needing
169+
it's currently unknown if they're thread safe. Due to no longer having or needing
166170
`__init__`, the case could be made here to not implement the Activities as a class,
167171
but just as decorated functions as shown here:
168172

0 commit comments

Comments
 (0)