{"id":14632,"library":"interruptingcow","title":"InterruptingCow","description":"Interruptingcow is a generic utility designed to gracefully interrupt Python code that exceeds a specified execution time. It achieves this by utilizing the `signal(SIGALRM)` mechanism. The current version is 0.8, with an infrequent release cadence, as the last update was in 2018.","status":"maintenance","version":"0.8","language":"en","source_language":"en","source_url":"https://github.com/erikvanzijst/interruptingcow","tags":["timeout","watchdog","signals","legacy-python","concurrency"],"install":[{"cmd":"pip install interruptingcow","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"timeout","correct":"from interruptingcow import timeout"},{"symbol":"Quota","correct":"from interruptingcow import Quota"}],"quickstart":{"code":"import time\nfrom interruptingcow import timeout\n\ntry:\n    with timeout(2, exception=RuntimeError):\n        print(\"Starting a 3-second operation...\")\n        time.sleep(3)\n        print(\"Operation completed.\") # This line will not be reached\nexcept RuntimeError:\n    print(\"Operation didn't finish within 2 seconds.\")\n\n# Example with quota\nfrom interruptingcow import Quota\nquota = Quota(1.0)\n\nfor i in range(5):\n    try:\n        with timeout(quota, RuntimeError):\n            print(f\"Iteration {i+1}: Performing expensive operation...\")\n            time.sleep(0.3) # Each takes 0.3s\n    except RuntimeError:\n        print(f\"Iteration {i+1}: Quota exceeded for expensive operation, doing cheaper thing.\")\n","lang":"python","description":"The primary use case is wrapping potentially long-running code in a `with timeout(...)` block. If the code inside the block exceeds the specified time, a `RuntimeError` (or a custom exception) is raised. Quotas can be used to limit total time across multiple calls."},"warnings":[{"fix":"Ensure critical sections requiring timeouts are run in the main thread or consider alternative asynchronous timeout mechanisms for multi-threaded applications (e.g., using `threading.Event` or `concurrent.futures`).","message":"Interruptingcow relies on `signal(SIGALRM)` for interruption, which is a C-level signal and only applies to the main thread in Python. Code running in other threads will not be interrupted by `timeout`.","severity":"breaking","affected_versions":"All versions (0.8 and earlier)"},{"fix":"Avoid using `interruptingcow` in applications that manage `SIGALRM` directly. If unavoidable, carefully manage signal handlers to prevent conflicts, e.g., by saving and restoring existing handlers.","message":"The library uses `SIGALRM` and should not be used in programs that also set their own `SIGALRM` handlers. This can lead to unexpected behavior or prevent either the library's timeout or your custom signal handler from working correctly.","severity":"breaking","affected_versions":"All versions (0.8 and earlier)"},{"fix":"For new projects or environments running Python 3.6+, it is strongly recommended to use a more actively maintained timeout library or Python's built-in `signal` module directly. If `interruptingcow` must be used, ensure compatibility by restricting the Python interpreter to version 3.5 or earlier in a virtual environment.","message":"Version 0.8 explicitly supports Python 2.7 and 3.5. It is known to rely on undocumented internal `contextlib` details (`GeneratorContextManager`) that changed or were removed in Python 3.6+ versions. This can cause `AttributeError` or other import/runtime failures on modern Python environments.","severity":"deprecated","affected_versions":"0.8 on Python 3.6+ environments"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"This library is designed for older Python versions (up to 3.5). Downgrade your Python environment to 3.5 or earlier, or migrate to a different, actively maintained timeout library compatible with modern Python versions.","cause":"This error occurs when `interruptingcow` attempts to import or use a class (`GeneratorContextManager`) from Python's internal `contextlib` module that was an undocumented implementation detail in Python 2 and removed/changed in Python 3.6+.","error":"AttributeError: 'module' object has no attribute 'GeneratorContextManager'"},{"fix":"Refactor your code to execute the timed operation within the main thread, or use an alternative inter-thread communication mechanism (e.g., `threading.Event`, `queue` with a timeout, or `concurrent.futures.wait` with a timeout) if the operation must be performed in a separate thread.","cause":"The `interruptingcow` library uses `signal(SIGALRM)` which only works reliably in the main thread of a Python process. Threads created via `threading` module will not receive these signals.","error":"My timeout doesn't work when I use threads, or my program hangs."}],"ecosystem":"pypi"}