Skip to content

Commit fde6ffb

Browse files
committed
Update examples.
1 parent f1e9358 commit fde6ffb

2 files changed

Lines changed: 14 additions & 24 deletions

File tree

README.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ if __name__ == "__main__":
121121
output_queue_count=1,
122122
dynamic_up_scaling=dynamic_scaling,
123123
dynamic_down_scaling=dynamic_scaling,
124+
spread_stop_signal=True,
124125
)
125126
# Configure the manager to generate 1 worker/process.
126127
data_printer_manager = DataPrinterManager(
@@ -142,19 +143,13 @@ if __name__ == "__main__":
142143
print("Controller pushed:", data)
143144
data_filter_manager.push_to_input_queue(data)
144145

145-
# Push the stop signal at the end of the input queue to stop the workers.
146-
# Note:
147-
# As the data printer is a dependency of the data filter, we don't need to
148-
# stop it explicitly. It will be stopped automatically when the data filter
149-
# manager stops.
146+
# If terminate the manager and all the managed workers after waiting for the
147+
# workers to finish processing the data.
150148
#
151-
data_filter_manager.push_stop_signal()
152-
# Wait for the manager to finish processing the data.
153-
data_filter_manager.wait()
154-
155-
# If we want to terminate the manager and all workers, we can call the
156-
# terminate method.
157-
data_filter_manager.terminate()
149+
# Note: In soft mode, the manager will wait for the workers to finish processing
150+
# the data before terminating them. In hard mode, the manager will terminate the
151+
# workers immediately.
152+
data_filter_manager.terminate(mode="soft")
158153

159154
print("Data filtered successfully.")
160155

examples/data_filter.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class DataPrinterManager(ProcessManagerCore):
143143
output_queue_count=1,
144144
dynamic_up_scaling=dynamic_scaling,
145145
dynamic_down_scaling=dynamic_scaling,
146+
spread_stop_signal=True,
146147
)
147148
# Configure the manager to generate 1 worker/process.
148149
data_printer_manager = DataPrinterManager(
@@ -164,18 +165,12 @@ class DataPrinterManager(ProcessManagerCore):
164165
print("Controller pushed:", data)
165166
data_filter_manager.push_to_input_queue(data)
166167

167-
# Push the stop signal at the end of the input queue to stop the workers.
168-
# Note:
169-
# As the data printer is a dependency of the data filter, we don't need to
170-
# stop it explicitly. It will be stopped automatically when the data filter
171-
# manager stops.
168+
# If terminate the manager and all the managed workers after waiting for the
169+
# workers to finish processing the data.
172170
#
173-
data_filter_manager.push_stop_signal()
174-
# Wait for the manager to finish processing the data.
175-
data_filter_manager.wait()
176-
177-
# If we want to terminate the manager and all workers, we can call the
178-
# terminate method.
179-
data_filter_manager.terminate()
171+
# Note: In soft mode, the manager will wait for the workers to finish processing
172+
# the data before terminating them. In hard mode, the manager will terminate the
173+
# workers immediately.
174+
data_filter_manager.terminate(mode="soft")
180175

181176
print("Data filtered successfully.")

0 commit comments

Comments
 (0)