tasq-client-python 0.1.13__tar.gz → 0.1.15__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tasq-client-python-0.1.13 → tasq-client-python-0.1.15}/PKG-INFO +2 -1
- {tasq-client-python-0.1.13 → tasq-client-python-0.1.15}/setup.py +1 -1
- {tasq-client-python-0.1.13 → tasq-client-python-0.1.15}/tasq_client/client.py +28 -17
- {tasq-client-python-0.1.13 → tasq-client-python-0.1.15}/tasq_client_python.egg-info/PKG-INFO +2 -1
- {tasq-client-python-0.1.13 → tasq-client-python-0.1.15}/README.md +0 -0
- {tasq-client-python-0.1.13 → tasq-client-python-0.1.15}/setup.cfg +0 -0
- {tasq-client-python-0.1.13 → tasq-client-python-0.1.15}/tasq_client/__init__.py +0 -0
- {tasq-client-python-0.1.13 → tasq-client-python-0.1.15}/tasq_client/check_type.py +0 -0
- {tasq-client-python-0.1.13 → tasq-client-python-0.1.15}/tasq_client/check_type_test.py +0 -0
- {tasq-client-python-0.1.13 → tasq-client-python-0.1.15}/tasq_client_python.egg-info/SOURCES.txt +0 -0
- {tasq-client-python-0.1.13 → tasq-client-python-0.1.15}/tasq_client_python.egg-info/dependency_links.txt +0 -0
- {tasq-client-python-0.1.13 → tasq-client-python-0.1.15}/tasq_client_python.egg-info/requires.txt +0 -0
- {tasq-client-python-0.1.13 → tasq-client-python-0.1.15}/tasq_client_python.egg-info/top_level.txt +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import multiprocessing
|
|
2
1
|
import random
|
|
3
2
|
import sys
|
|
4
3
|
import time
|
|
5
4
|
import urllib.parse
|
|
6
5
|
from contextlib import contextmanager
|
|
7
6
|
from dataclasses import dataclass
|
|
8
|
-
from
|
|
7
|
+
from queue import Empty, Queue
|
|
8
|
+
from threading import Thread
|
|
9
9
|
from typing import Any, Dict, List, Optional, Tuple
|
|
10
10
|
|
|
11
11
|
import requests
|
|
@@ -35,6 +35,8 @@ class QueueCounts:
|
|
|
35
35
|
# server is old enough to not support rate estimation.
|
|
36
36
|
rate: Optional[float] = None
|
|
37
37
|
|
|
38
|
+
modtime: Optional[int] = None
|
|
39
|
+
|
|
38
40
|
|
|
39
41
|
class TasqClient:
|
|
40
42
|
"""
|
|
@@ -82,7 +84,6 @@ class TasqClient:
|
|
|
82
84
|
self.retry_server_errors = retry_server_errors
|
|
83
85
|
self.session = requests.Session()
|
|
84
86
|
self._configure_session()
|
|
85
|
-
self.mp_context = multiprocessing.get_context("spawn")
|
|
86
87
|
|
|
87
88
|
def push(self, contents: str, limit: int = 0) -> Optional[str]:
|
|
88
89
|
"""
|
|
@@ -240,9 +241,7 @@ class TasqClient:
|
|
|
240
241
|
while True:
|
|
241
242
|
task, timeout = self.pop()
|
|
242
243
|
if task is not None:
|
|
243
|
-
rt = RunningTask(
|
|
244
|
-
self, id=task.id, contents=task.contents, mp_context=self.mp_context
|
|
245
|
-
)
|
|
244
|
+
rt = RunningTask(self, id=task.id, contents=task.contents)
|
|
246
245
|
try:
|
|
247
246
|
yield rt
|
|
248
247
|
rt.completed()
|
|
@@ -258,7 +257,7 @@ class TasqClient:
|
|
|
258
257
|
def counts(self, rate_window: int = 0) -> QueueCounts:
|
|
259
258
|
"""Get the number of tasks in each state within the queue."""
|
|
260
259
|
data = self._get(
|
|
261
|
-
f"/counts?window={rate_window}",
|
|
260
|
+
f"/counts?window={rate_window}&includeModtime=1",
|
|
262
261
|
{
|
|
263
262
|
"pending": int,
|
|
264
263
|
"running": int,
|
|
@@ -339,28 +338,28 @@ class RunningTask(Task):
|
|
|
339
338
|
cancel() or completed() is called.
|
|
340
339
|
"""
|
|
341
340
|
|
|
342
|
-
def __init__(
|
|
343
|
-
self, client: TasqClient, *args, mp_context: Optional[BaseContext] = None, **kwargs
|
|
344
|
-
):
|
|
341
|
+
def __init__(self, client: TasqClient, *args, **kwargs):
|
|
345
342
|
super().__init__(*args, **kwargs)
|
|
346
343
|
self.client = client
|
|
347
|
-
self.
|
|
344
|
+
self._kill_queue = Queue()
|
|
345
|
+
self._thread = Thread(
|
|
348
346
|
target=RunningTask._keepalive_worker,
|
|
349
347
|
name="tasq-keepalive-worker",
|
|
350
348
|
args=(
|
|
349
|
+
self._kill_queue,
|
|
351
350
|
client,
|
|
352
351
|
self.id,
|
|
353
352
|
),
|
|
354
353
|
daemon=True,
|
|
355
354
|
)
|
|
356
|
-
self.
|
|
355
|
+
self._thread.start()
|
|
357
356
|
|
|
358
357
|
def cancel(self):
|
|
359
|
-
if self.
|
|
358
|
+
if self._thread is None:
|
|
360
359
|
return
|
|
361
|
-
self.
|
|
362
|
-
self.
|
|
363
|
-
self.
|
|
360
|
+
self._kill_queue.put(None)
|
|
361
|
+
self._thread.join()
|
|
362
|
+
self._thread = None
|
|
364
363
|
|
|
365
364
|
def completed(self):
|
|
366
365
|
self.cancel()
|
|
@@ -368,6 +367,7 @@ class RunningTask(Task):
|
|
|
368
367
|
|
|
369
368
|
@staticmethod
|
|
370
369
|
def _keepalive_worker(
|
|
370
|
+
kill_queue: Queue,
|
|
371
371
|
client: TasqClient,
|
|
372
372
|
task_id: str,
|
|
373
373
|
):
|
|
@@ -375,8 +375,19 @@ class RunningTask(Task):
|
|
|
375
375
|
try:
|
|
376
376
|
client.keepalive(task_id)
|
|
377
377
|
except Exception as exc: # pylint: disable=broad-except
|
|
378
|
+
# Ignore the error if we killed the thread during the
|
|
379
|
+
# keepalive call.
|
|
380
|
+
try:
|
|
381
|
+
kill_queue.get(block=False)
|
|
382
|
+
return
|
|
383
|
+
except Empty:
|
|
384
|
+
pass
|
|
378
385
|
print(f"exception in tasq keepalive worker: {exc}", file=sys.stderr)
|
|
379
|
-
|
|
386
|
+
try:
|
|
387
|
+
kill_queue.get(timeout=client.keepalive_interval)
|
|
388
|
+
return
|
|
389
|
+
except Empty:
|
|
390
|
+
pass
|
|
380
391
|
|
|
381
392
|
|
|
382
393
|
class TasqRemoteError(Exception):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{tasq-client-python-0.1.13 → tasq-client-python-0.1.15}/tasq_client_python.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{tasq-client-python-0.1.13 → tasq-client-python-0.1.15}/tasq_client_python.egg-info/requires.txt
RENAMED
|
File without changes
|
{tasq-client-python-0.1.13 → tasq-client-python-0.1.15}/tasq_client_python.egg-info/top_level.txt
RENAMED
|
File without changes
|