diff --git a/.docs/description.rst b/.docs/description.rst index c0a4d86..13748a0 100644 --- a/.docs/description.rst +++ b/.docs/description.rst @@ -2,8 +2,7 @@ There are several timeout decorators available, but the one mentioned here focuses on ensuring correctness when used with classes, methods, class methods, static methods, etc. It also preserves traceback information for PyCharm debugging. -Additionally, there is a powerful eval function that allows reading -the desired timeout value even from class attributes. +The timeout can be dynamically adjusted, calculated from other parameters or methods accessible via an optional eval function. Two timeout strategies have been implemented: one using "Signals" and the other using "Subprocess". diff --git a/.docs/installation.rst b/.docs/installation.rst index 84bc76a..c6f0b64 100644 --- a/.docs/installation.rst +++ b/.docs/installation.rst @@ -1,10 +1,9 @@ -- Before You start, its highly recommended to update pip and setup tools: +- Before You start, its highly recommended to update pip: .. code-block:: python -m pip --upgrade pip - python -m pip --upgrade setuptools .. include:: ./installation_via_pypi.rst diff --git a/.docs/parts/01_basic_usage.rst b/.docs/parts/01_basic_usage.rst index f29fd05..72972b1 100644 --- a/.docs/parts/01_basic_usage.rst +++ b/.docs/parts/01_basic_usage.rst @@ -1,7 +1,7 @@ Basic Usage ----------- -.. code-block:: +.. code-block:: python import time from wrapt_timeout_decorator import * diff --git a/.docs/parts/02_general_recommendations.rst b/.docs/parts/02_general_recommendations.rst index d579541..4ae5b72 100644 --- a/.docs/parts/02_general_recommendations.rst +++ b/.docs/parts/02_general_recommendations.rst @@ -1,23 +1,5 @@ General Recommendations ----------------------- -It is advised to limit the use of timeouts in your code, applying them only in critical situations. - -Ensure that timeouts are implemented at the right granular level which is specific to Your application. - -On one hand, this approach helps in avoiding undesired effects, such as exceptions being intercepted by unrelated segments of code, -or issues with non-pickable entities. - -On the other hand, incorporating a Timeout Decorator within a repetitive loop should be avoided. -This practice can lead to significant delays, particularly on Windows platforms -due to the overhead associated with spawning subprocesses. - -Preferably, make use of the native timeouts provided by the functions and libraries you are working with. -These built-in mechanisms typically suffice for most scenarios. -The Timeout Decorator should only be considered as a fallback option, after all other possibilities have been thoroughly explored. - -Be aware that the isolation and performance of subprocesses can be very different, depending on the Platform (Windows or Linux) and the selected subprecess -start method. - see STARTMETHOD - It's recommended to minimize the utilization of timeouts in your programming, reserving them for truly essential instances. @@ -35,12 +17,12 @@ subsequent to the exhaustive consideration of alternative strategies. Additionally, be cognizant of the fact that the behavior and efficiency of subprocesses may vary significantly across platforms (Windows versus Linux) and depending on the chosen method for subprocess initiation. -Refer to the documentation on STARTMETHOD for further details. +Refer to the documentation on `Subprocess Start Methods`_ for further details. BAD EXAMPLE (Pseudocode) - lets assume the write to the database fails sometimes for unknown reasons, and "hangs" - .. code-block:: py + .. code-block:: python # module file_analyzer import time @@ -65,7 +47,7 @@ Refer to the documentation on STARTMETHOD for further details. BETTER EXAMPLE (Pseudocode) - .. code-block:: py + .. code-block:: python # module file_analyzer import time diff --git a/.docs/parts/03_use_with_windows.rst b/.docs/parts/03_use_with_windows.rst index 971e478..ee3dd7c 100644 --- a/.docs/parts/03_use_with_windows.rst +++ b/.docs/parts/03_use_with_windows.rst @@ -66,7 +66,7 @@ An illustration highlights a scenario functional on Linux but problematic on Win where the variable `"name"` and the function `"sleep"` are not recognized in the spawned process: -.. code-block:: +.. code-block:: python main.py: @@ -93,7 +93,7 @@ where the variable `"name"` and the function `"sleep"` are not recognized in the here the same example, which will work on Windows: -.. code-block:: +.. code-block:: python # my_program_main.py: @@ -107,7 +107,7 @@ here the same example, which will work on Windows: main() -.. code-block:: +.. code-block:: python # conf_my_program.py: @@ -119,7 +119,7 @@ here the same example, which will work on Windows: conf_my_program = ConfMyProgram() -.. code-block:: +.. code-block:: python # lib_test.py: diff --git a/.docs/parts/04_considerations_using_signals.rst b/.docs/parts/04_considerations_using_signals.rst index d9b2719..297d56d 100644 --- a/.docs/parts/04_considerations_using_signals.rst +++ b/.docs/parts/04_considerations_using_signals.rst @@ -11,7 +11,7 @@ For an illustrative example, you're encouraged to conduct an experiment using a `Jupyter notebook `_. -.. code-block:: +.. code-block:: python import time from wrapt_timeout_decorator import * diff --git a/.docs/parts/05_considerations_using_subprocesses.rst b/.docs/parts/05_considerations_using_subprocesses.rst index c43e6cd..9bcf321 100644 --- a/.docs/parts/05_considerations_using_subprocesses.rst +++ b/.docs/parts/05_considerations_using_subprocesses.rst @@ -35,11 +35,13 @@ Choosing the Right Start Method Setting the Start Method ------------------------ -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. +Configure the start method with ``multiprocessing.set_start_method(method, force=True)``. This should be done cautiously, ideally once, and within the ``if +__name__ == '__main__'`` block to prevent unintended effects. Since we use ``multiprocess`` instead of ``multiprocessing``, we provide a method to set the starting method on both at the same time. see : `set_subprocess_starting_method`_ 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. -You can set that by using the parameter `dec_mp_reset_signals` +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. +You can set that by passing the parameter ``dec_mp_reset_signals=True`` to the decorator. diff --git a/.docs/parts/06_nested_timeouts.rst b/.docs/parts/06_nested_timeouts.rst index 7a9a068..7f55fa3 100644 --- a/.docs/parts/06_nested_timeouts.rst +++ b/.docs/parts/06_nested_timeouts.rst @@ -8,7 +8,7 @@ For practical experimentation and to see this behavior in action, you're encouraged to use a `Jupyter notebook `_. -.. code-block:: +.. code-block:: python # main.py import mylib @@ -20,7 +20,7 @@ you're encouraged to use a `Jupyter notebook `_. -.. code-block:: +.. code-block:: python import time from wrapt_timeout_decorator import * @@ -512,14 +493,16 @@ Choosing the Right Start Method Setting the Start Method ------------------------ -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. +Configure the start method with ``multiprocessing.set_start_method(method, force=True)``. This should be done cautiously, ideally once, and within the ``if +__name__ == '__main__'`` block to prevent unintended effects. Since we use ``multiprocess`` instead of ``multiprocessing``, we provide a method to set the starting method on both at the same time. see : `set_subprocess_starting_method`_ 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. -You can set that by using the parameter `dec_mp_reset_signals` +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. +You can set that by passing the parameter ``dec_mp_reset_signals=True`` to the decorator. Handling Nested Timeouts ------------------------ @@ -531,7 +514,7 @@ For practical experimentation and to see this behavior in action, you're encouraged to use a `Jupyter notebook `_. -.. code-block:: +.. code-block:: python # main.py import mylib @@ -543,7 +526,7 @@ you're encouraged to use a `Jupyter notebook