From d95687d6453883e44f6587c8553f7fa130becd77 Mon Sep 17 00:00:00 2001 From: isra17 Date: Fri, 5 May 2023 15:23:04 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20Flared/d?= =?UTF-8?q?ramatiq-abort@b53f1287c2a62e1aa45ee0b96a18154d10610133=20?= =?UTF-8?q?=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _sources/index.rst.txt | 1 + index.html | 15 +++++++++++++++ searchindex.js | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/_sources/index.rst.txt b/_sources/index.rst.txt index 8e6874f..a0027b9 100644 --- a/_sources/index.rst.txt +++ b/_sources/index.rst.txt @@ -113,6 +113,7 @@ When a worker is waiting on a subprocess, the :any:`Abort` exception will only b AFTER the subprocess has been completed. The following example is one way to deal with this: .. code-block:: + @dramatiq.actor def my_subprocess(): with subprocess.Popen(*args, **kwargs) as process: diff --git a/index.html b/index.html index c240e91..0a0649c 100644 --- a/index.html +++ b/index.html @@ -128,6 +128,21 @@

Abort a task using a custom abort_ttl value

When a worker is waiting on a subprocess, the Abort exception will only be raised AFTER the subprocess has been completed. The following example is one way to deal with this:

+
@dramatiq.actor
+def my_subprocess():
+  with subprocess.Popen(*args, **kwargs) as process:
+    ret = None
+    try:
+      while ret is None:
+        try:
+          ret = process.wait(timeout=1)  # Note: same principle for `process.communicate()`
+        except subprocess.TimeoutExpired:
+          pass
+    except Abort:
+      process.signal(signal.SIGINT)  # or on windows: `os.kill(process.pid, signal.SIGINT)`
+      process.wait()
+
+

API

diff --git a/searchindex.js b/searchindex.js index eb07f98..99d63bc 100644 --- a/searchindex.js +++ b/searchindex.js @@ -1 +1 @@ -Search.setIndex({"docnames": ["index"], "filenames": ["index.rst"], "titles": ["dramatiq-abort"], "terms": {"document": 0, "sourc": 0, "when": 0, "might": 0, "enqueu": 0, "even": 0, "actor": 0, "The": 0, "middlewar": 0, "allow": 0, "signal": 0, "termin": 0, "from": 0, "ani": 0, "client": 0, "distribut": 0, "event": 0, "backend": 0, "At": 0, "moment": 0, "onli": 0, "redi": 0, "exist": 0, "provid": 0, "simpl": 0, "interfac": 0, "add": 0, "more": 0, "pip": 0, "i": 0, "creat": 0, "object": 0, "ad": 0, "broker": 0, "instanc": 0, "import": 0, "get_brok": 0, "dramatiq_abort": 0, "event_backend": 0, "redisbackend": 0, "add_middlewar": 0, "an": 0, "sent": 0, "worker": 0, "messag": 0, "return": 0, "id": 0, "thi": 0, "can": 0, "kept": 0, "somewher": 0, "so": 0, "two": 0, "mode": 0, "cancel": 0, "pend": 0, "def": 0, "my_long_running_task": 0, "send": 0, "message_id": 0, "default": 0, "abortmod": 0, "set": 0, "option": 0, "timeout": 0, "finish": 0, "befor": 0, "being": 0, "check": 0, "request": 0, "call": 0, "abort_request": 0, "which": 0, "number": 0, "millisecond": 0, "until": 0, "none": 0, "while": 0, "true": 0, "sleep": 0, "0": 0, "1": 0, "do": 0, "work": 0, "break": 0, "stop": 0, "2": 0, "second": 0, "abort_timeout": 0, "2000": 0, "By": 0, "ha": 0, "limit": 0, "window": 0, "90": 0, "000": 0, "mean": 0, "skip": 0, "wa": 0, "up": 0, "ago": 0, "In": 0, "case": 0, "longer": 0, "delai": 0, "process": 0, "overridden": 0, "count_word": 0, "url": 0, "send_with_opt": 0, "arg": 0, "http": 0, "exampl": 0, "com": 0, "60": 0, "1000": 0, "wait": 0, "except": 0, "rais": 0, "after": 0, "been": 0, "complet": 0, "follow": 0, "one": 0, "wai": 0, "deal": 0, "given": 0, "its": 0, "paramet": 0, "str": 0, "attribut": 0, "If": 0, "retriev": 0, "runtimeerror": 0, "int": 0, "chang": 0, "ttl": 0, "argument": 0, "also": 0, "addition": 0, "applic": 0, "type": 0, "current": 0, "via": 0, "instead": 0, "As": 0, "float": 0, "class": 0, "90000": 0, "interrupt": 0, "whose": 0, "job": 0, "avail": 0, "cpython": 0, "prioriti": 0, "respect": 0, "note": 0, "async": 0, "thread": 0, "get": 0, "next": 0, "time": 0, "acquir": 0, "gil": 0, "concret": 0, "t": 0, "system": 0, "eventbackend": 0, "see": 0, "bool": 0, "everi": 0, "have": 0, "kei": 0, "param": 0, "dict": 0, "ar": 0, "compos": 0, "identifi": 0, "associ": 0, "abc": 0, "abstract": 0, "notifi": 0, "onc": 0, "poll": 0, "wait_mani": 0, "should": 0, "result": 0, "posit": 0, "live": 0, "larg": 0, "enough": 0, "give": 0, "small": 0, "doesn": 0, "end": 0, "too": 0, "mani": 0, "outdat": 0, "garbag": 0, "collect": 0, "iter": 0, "function": 0, "block": 0, "otherwis": 0, "A": 0, "idempot": 0, "subsequ": 0, "either": 0, "elaps": 0, "indefinit": 0, "list": 0, "maximum": 0, "amount": 0, "namespac": 0, "prefix": 0, "classmethod": 0, "from_url": 0, "kwarg": 0, "initi": 0, "server": 0, "extra": 0, "pass": 0, "constructor": 0}, "objects": {"": [[0, 0, 0, "-", "dramatiq-abort"], [0, 0, 0, "-", "dramatiq_abort"]], "dramatiq_abort": [[0, 1, 1, "", "Abort"], [0, 1, 1, "", "Abortable"], [0, 1, 1, "", "Event"], [0, 1, 1, "", "EventBackend"], [0, 3, 1, "", "abort"], [0, 3, 1, "", "abort_requested"], [0, 0, 0, "-", "backends"]], "dramatiq_abort.EventBackend": [[0, 2, 1, "", "notify"], [0, 2, 1, "", "poll"], [0, 2, 1, "", "wait_many"]], "dramatiq_abort.backends": [[0, 1, 1, "", "RedisBackend"]], "dramatiq_abort.backends.RedisBackend": [[0, 2, 1, "", "from_url"]]}, "objtypes": {"0": "py:module", "1": "py:class", "2": "py:method", "3": "py:function"}, "objnames": {"0": ["py", "module", "Python module"], "1": ["py", "class", "Python class"], "2": ["py", "method", "Python method"], "3": ["py", "function", "Python function"]}, "titleterms": {"dramatiq": 0, "abort": 0, "instal": 0, "configur": 0, "task": 0, "gracefulli": 0, "us": 0, "custom": 0, "abort_ttl": 0, "valu": 0, "run": 0, "subprocess": 0, "api": 0}, "envversion": {"sphinx.domains.c": 2, "sphinx.domains.changeset": 1, "sphinx.domains.citation": 1, "sphinx.domains.cpp": 8, "sphinx.domains.index": 1, "sphinx.domains.javascript": 2, "sphinx.domains.math": 2, "sphinx.domains.python": 3, "sphinx.domains.rst": 2, "sphinx.domains.std": 2, "sphinx": 57}, "alltitles": {"dramatiq-abort": [[0, "dramatiq-abort"]], "Installing dramatiq-abort": [[0, "installing-dramatiq-abort"]], "Configuring dramatiq-abort": [[0, "configuring-dramatiq-abort"]], "Abort a task": [[0, "abort-a-task"]], "Gracefully aborting tasks": [[0, "gracefully-aborting-tasks"]], "Abort a task using a custom abort_ttl value": [[0, "abort-a-task-using-a-custom-abort-ttl-value"]], "Abort a task running a subprocess": [[0, "abort-a-task-running-a-subprocess"]], "API": [[0, "module-dramatiq_abort"]]}, "indexentries": {"abort (class in dramatiq_abort)": [[0, "dramatiq_abort.Abort"]], "abortable (class in dramatiq_abort)": [[0, "dramatiq_abort.Abortable"]], "event (class in dramatiq_abort)": [[0, "dramatiq_abort.Event"]], "eventbackend (class in dramatiq_abort)": [[0, "dramatiq_abort.EventBackend"]], "redisbackend (class in dramatiq_abort.backends)": [[0, "dramatiq_abort.backends.RedisBackend"]], "abort() (in module dramatiq_abort)": [[0, "dramatiq_abort.abort"]], "abort_requested() (in module dramatiq_abort)": [[0, "dramatiq_abort.abort_requested"]], "dramatiq-abort": [[0, "module-dramatiq-abort"]], "dramatiq_abort": [[0, "module-dramatiq_abort"]], "dramatiq_abort.backends": [[0, "module-dramatiq_abort.backends"]], "from_url() (dramatiq_abort.backends.redisbackend class method)": [[0, "dramatiq_abort.backends.RedisBackend.from_url"]], "module": [[0, "module-dramatiq-abort"], [0, "module-dramatiq_abort"], [0, "module-dramatiq_abort.backends"]], "notify() (dramatiq_abort.eventbackend method)": [[0, "dramatiq_abort.EventBackend.notify"]], "poll() (dramatiq_abort.eventbackend method)": [[0, "dramatiq_abort.EventBackend.poll"]], "wait_many() (dramatiq_abort.eventbackend method)": [[0, "dramatiq_abort.EventBackend.wait_many"]]}}) \ No newline at end of file +Search.setIndex({"docnames": ["index"], "filenames": ["index.rst"], "titles": ["dramatiq-abort"], "terms": {"document": 0, "sourc": 0, "when": 0, "might": 0, "enqueu": 0, "even": 0, "actor": 0, "The": 0, "middlewar": 0, "allow": 0, "signal": 0, "termin": 0, "from": 0, "ani": 0, "client": 0, "distribut": 0, "event": 0, "backend": 0, "At": 0, "moment": 0, "onli": 0, "redi": 0, "exist": 0, "provid": 0, "simpl": 0, "interfac": 0, "add": 0, "more": 0, "pip": 0, "i": 0, "creat": 0, "object": 0, "ad": 0, "broker": 0, "instanc": 0, "import": 0, "get_brok": 0, "dramatiq_abort": 0, "event_backend": 0, "redisbackend": 0, "add_middlewar": 0, "an": 0, "sent": 0, "worker": 0, "messag": 0, "return": 0, "id": 0, "thi": 0, "can": 0, "kept": 0, "somewher": 0, "so": 0, "two": 0, "mode": 0, "cancel": 0, "pend": 0, "def": 0, "my_long_running_task": 0, "send": 0, "message_id": 0, "default": 0, "abortmod": 0, "set": 0, "option": 0, "timeout": 0, "finish": 0, "befor": 0, "being": 0, "check": 0, "request": 0, "call": 0, "abort_request": 0, "which": 0, "number": 0, "millisecond": 0, "until": 0, "none": 0, "while": 0, "true": 0, "sleep": 0, "0": 0, "1": 0, "do": 0, "work": 0, "break": 0, "stop": 0, "2": 0, "second": 0, "abort_timeout": 0, "2000": 0, "By": 0, "ha": 0, "limit": 0, "window": 0, "90": 0, "000": 0, "mean": 0, "skip": 0, "wa": 0, "up": 0, "ago": 0, "In": 0, "case": 0, "longer": 0, "delai": 0, "process": 0, "overridden": 0, "count_word": 0, "url": 0, "send_with_opt": 0, "arg": 0, "http": 0, "exampl": 0, "com": 0, "60": 0, "1000": 0, "wait": 0, "except": 0, "rais": 0, "after": 0, "been": 0, "complet": 0, "follow": 0, "one": 0, "wai": 0, "deal": 0, "my_subprocess": 0, "popen": 0, "kwarg": 0, "ret": 0, "try": 0, "note": 0, "same": 0, "principl": 0, "commun": 0, "timeoutexpir": 0, "pass": 0, "sigint": 0, "o": 0, "kill": 0, "pid": 0, "given": 0, "its": 0, "paramet": 0, "str": 0, "attribut": 0, "If": 0, "retriev": 0, "runtimeerror": 0, "int": 0, "chang": 0, "ttl": 0, "argument": 0, "also": 0, "addition": 0, "applic": 0, "type": 0, "current": 0, "via": 0, "instead": 0, "As": 0, "float": 0, "class": 0, "90000": 0, "interrupt": 0, "whose": 0, "job": 0, "avail": 0, "cpython": 0, "prioriti": 0, "respect": 0, "async": 0, "thread": 0, "get": 0, "next": 0, "time": 0, "acquir": 0, "gil": 0, "concret": 0, "t": 0, "system": 0, "eventbackend": 0, "see": 0, "bool": 0, "everi": 0, "have": 0, "kei": 0, "param": 0, "dict": 0, "ar": 0, "compos": 0, "identifi": 0, "associ": 0, "abc": 0, "abstract": 0, "notifi": 0, "onc": 0, "poll": 0, "wait_mani": 0, "should": 0, "result": 0, "posit": 0, "live": 0, "larg": 0, "enough": 0, "give": 0, "small": 0, "doesn": 0, "end": 0, "too": 0, "mani": 0, "outdat": 0, "garbag": 0, "collect": 0, "iter": 0, "function": 0, "block": 0, "otherwis": 0, "A": 0, "idempot": 0, "subsequ": 0, "either": 0, "elaps": 0, "indefinit": 0, "list": 0, "maximum": 0, "amount": 0, "namespac": 0, "prefix": 0, "classmethod": 0, "from_url": 0, "initi": 0, "server": 0, "extra": 0, "constructor": 0}, "objects": {"": [[0, 0, 0, "-", "dramatiq-abort"], [0, 0, 0, "-", "dramatiq_abort"]], "dramatiq_abort": [[0, 1, 1, "", "Abort"], [0, 1, 1, "", "Abortable"], [0, 1, 1, "", "Event"], [0, 1, 1, "", "EventBackend"], [0, 3, 1, "", "abort"], [0, 3, 1, "", "abort_requested"], [0, 0, 0, "-", "backends"]], "dramatiq_abort.EventBackend": [[0, 2, 1, "", "notify"], [0, 2, 1, "", "poll"], [0, 2, 1, "", "wait_many"]], "dramatiq_abort.backends": [[0, 1, 1, "", "RedisBackend"]], "dramatiq_abort.backends.RedisBackend": [[0, 2, 1, "", "from_url"]]}, "objtypes": {"0": "py:module", "1": "py:class", "2": "py:method", "3": "py:function"}, "objnames": {"0": ["py", "module", "Python module"], "1": ["py", "class", "Python class"], "2": ["py", "method", "Python method"], "3": ["py", "function", "Python function"]}, "titleterms": {"dramatiq": 0, "abort": 0, "instal": 0, "configur": 0, "task": 0, "gracefulli": 0, "us": 0, "custom": 0, "abort_ttl": 0, "valu": 0, "run": 0, "subprocess": 0, "api": 0}, "envversion": {"sphinx.domains.c": 2, "sphinx.domains.changeset": 1, "sphinx.domains.citation": 1, "sphinx.domains.cpp": 8, "sphinx.domains.index": 1, "sphinx.domains.javascript": 2, "sphinx.domains.math": 2, "sphinx.domains.python": 3, "sphinx.domains.rst": 2, "sphinx.domains.std": 2, "sphinx": 57}, "alltitles": {"dramatiq-abort": [[0, "dramatiq-abort"]], "Installing dramatiq-abort": [[0, "installing-dramatiq-abort"]], "Configuring dramatiq-abort": [[0, "configuring-dramatiq-abort"]], "Abort a task": [[0, "abort-a-task"]], "Gracefully aborting tasks": [[0, "gracefully-aborting-tasks"]], "Abort a task using a custom abort_ttl value": [[0, "abort-a-task-using-a-custom-abort-ttl-value"]], "Abort a task running a subprocess": [[0, "abort-a-task-running-a-subprocess"]], "API": [[0, "module-dramatiq_abort"]]}, "indexentries": {"abort (class in dramatiq_abort)": [[0, "dramatiq_abort.Abort"]], "abortable (class in dramatiq_abort)": [[0, "dramatiq_abort.Abortable"]], "event (class in dramatiq_abort)": [[0, "dramatiq_abort.Event"]], "eventbackend (class in dramatiq_abort)": [[0, "dramatiq_abort.EventBackend"]], "redisbackend (class in dramatiq_abort.backends)": [[0, "dramatiq_abort.backends.RedisBackend"]], "abort() (in module dramatiq_abort)": [[0, "dramatiq_abort.abort"]], "abort_requested() (in module dramatiq_abort)": [[0, "dramatiq_abort.abort_requested"]], "dramatiq-abort": [[0, "module-dramatiq-abort"]], "dramatiq_abort": [[0, "module-dramatiq_abort"]], "dramatiq_abort.backends": [[0, "module-dramatiq_abort.backends"]], "from_url() (dramatiq_abort.backends.redisbackend class method)": [[0, "dramatiq_abort.backends.RedisBackend.from_url"]], "module": [[0, "module-dramatiq-abort"], [0, "module-dramatiq_abort"], [0, "module-dramatiq_abort.backends"]], "notify() (dramatiq_abort.eventbackend method)": [[0, "dramatiq_abort.EventBackend.notify"]], "poll() (dramatiq_abort.eventbackend method)": [[0, "dramatiq_abort.EventBackend.poll"]], "wait_many() (dramatiq_abort.eventbackend method)": [[0, "dramatiq_abort.EventBackend.wait_many"]]}}) \ No newline at end of file