Adds timeout mechanism for workers

Workers now share a ctype with the sentinel to indicate if they are currently executing a task.  This timer is incremented each guard loop until the worker resets it after finishing a job or until it reaches the TIMEOUT value and the worker is terminated by the sentinel.
This commit is contained in:
Ilan Steemers
2015-07-01 10:54:36 +02:00
parent 5937f55fc5
commit 4e38925cea
4 changed files with 23 additions and 11 deletions
+3 -3
View File
@@ -1,6 +1,6 @@
import sys
import os
from multiprocessing import Queue, Event
from multiprocessing import Queue, Event, Value
import pytest
@@ -74,7 +74,7 @@ def test_cluster(r):
assert r.llen(list_key) == 0
# Test work
task_queue.put('STOP')
worker(task_queue, result_queue)
worker(task_queue, result_queue, Value('b', -1))
assert task_queue.qsize() == 0
assert result_queue.qsize() == 1
# Test monitor
@@ -131,7 +131,7 @@ def test_async(r):
task_queue.put('STOP')
# let a worker handle them
result_queue = Queue()
worker(task_queue, result_queue)
worker(task_queue, result_queue, Value('b', -1))
assert result_queue.qsize() == task_count
result_queue.put('STOP')
# store the results
+2 -2
View File
@@ -1,4 +1,4 @@
from multiprocessing import Queue, Event
from multiprocessing import Queue, Event, Value
import pytest
@@ -34,7 +34,7 @@ def test_scheduler(r):
task_queue.put('STOP')
# let a worker handle them
result_queue = Queue()
worker(task_queue, result_queue)
worker(task_queue, result_queue, Value('b', -1))
assert result_queue.qsize() == 1
result_queue.put('STOP')
# store the results