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/parts/02_general_recommendations.rst
+3-21Lines changed: 3 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,23 +1,5 @@
1
1
General Recommendations
2
2
-----------------------
3
-
It is advised to limit the use of timeouts in your code, applying them only in critical situations.
4
-
5
-
Ensure that timeouts are implemented at the right granular level which is specific to Your application.
6
-
7
-
On one hand, this approach helps in avoiding undesired effects, such as exceptions being intercepted by unrelated segments of code,
8
-
or issues with non-pickable entities.
9
-
10
-
On the other hand, incorporating a Timeout Decorator within a repetitive loop should be avoided.
11
-
This practice can lead to significant delays, particularly on Windows platforms
12
-
due to the overhead associated with spawning subprocesses.
13
-
14
-
Preferably, make use of the native timeouts provided by the functions and libraries you are working with.
15
-
These built-in mechanisms typically suffice for most scenarios.
16
-
The Timeout Decorator should only be considered as a fallback option, after all other possibilities have been thoroughly explored.
17
-
18
-
Be aware that the isolation and performance of subprocesses can be very different, depending on the Platform (Windows or Linux) and the selected subprecess
19
-
start method. - see STARTMETHOD
20
-
21
3
22
4
It's recommended to minimize the utilization of timeouts in your programming, reserving them for truly essential instances.
23
5
@@ -35,12 +17,12 @@ subsequent to the exhaustive consideration of alternative strategies.
35
17
36
18
Additionally, be cognizant of the fact that the behavior and efficiency of subprocesses may vary significantly across platforms
37
19
(Windows versus Linux) and depending on the chosen method for subprocess initiation.
38
-
Refer to the documentation on STARTMETHOD for further details.
20
+
Refer to the documentation on `Subprocess Start Methods`_ for further details.
39
21
40
22
41
23
BAD EXAMPLE (Pseudocode) - lets assume the write to the database fails sometimes for unknown reasons, and "hangs"
42
24
43
-
.. code-block:: py
25
+
.. code-block:: python
44
26
45
27
# module file_analyzer
46
28
import time
@@ -65,7 +47,7 @@ Refer to the documentation on STARTMETHOD for further details.
Copy file name to clipboardExpand all lines: .docs/parts/05_considerations_using_subprocesses.rst
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,11 +35,13 @@ Choosing the Right Start Method
35
35
36
36
Setting the Start Method
37
37
------------------------
38
-
Configure the start method with ``multiprocessing.set_start_method(method, force=False)``. This should be done cautiously, ideally once, and within the ``if __name__ == '__main__'`` block to prevent unintended effects.
38
+
Configure the start method with ``multiprocessing.set_start_method(method, force=True)``. This should be done cautiously, ideally once, and within the ``if
39
+
__name__ == '__main__'`` block to prevent unintended effects.
39
40
Since we use ``multiprocess`` instead of ``multiprocessing``, we provide a method to set the starting method on both at the same time.
40
41
see : `set_subprocess_starting_method`_
41
42
42
43
Special Considerations for Uvicorn, FastAPI, asyncio
For Uvicorn or FastAPI applications, a specific approach to the `fork` method is recommended to ensure proper signal handling and isolation, facilitated by the `dec_mp_reset_signals` parameter. This design aims to reset signal handlers and manage file descriptors in child processes effectively.
45
-
You can set that by using the parameter `dec_mp_reset_signals`
45
+
For Uvicorn or FastAPI applications, a specific approach to the `fork` method is recommended to ensure proper signal handling and isolation, facilitated by the ``dec_mp_reset_signals`` parameter.
46
+
This design aims to reset signal handlers and manage file descriptors in child processes effectively.
47
+
You can set that by passing the parameter ``dec_mp_reset_signals=True`` to the decorator.
Copy file name to clipboardExpand all lines: .docs/parts/06_nested_timeouts.rst
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ For practical experimentation and to see this behavior in action,
8
8
you're encouraged to use a `Jupyter notebook <https://mybinder.org/v2/gh/bitranox/wrapt_timeout_decorator/master?filepath=jupyter_test_{repository}.ipynb>`_.
9
9
10
10
11
-
.. code-block::
11
+
.. code-block::python
12
12
13
13
# main.py
14
14
import mylib
@@ -20,7 +20,7 @@ you're encouraged to use a `Jupyter notebook <https://mybinder.org/v2/gh/bitrano
0 commit comments