| 1 |
# AsynQueue: |
|---|
| 2 |
# Asynchronous task queueing based on the Twisted framework, with task |
|---|
| 3 |
# prioritization and a powerful worker/manager interface. |
|---|
| 4 |
# |
|---|
| 5 |
# Copyright (C) 2006-2007 by Edwin A. Suominen, http://www.eepatents.com |
|---|
| 6 |
# |
|---|
| 7 |
# This program is free software; you can redistribute it and/or modify it under |
|---|
| 8 |
# the terms of the GNU General Public License as published by the Free Software |
|---|
| 9 |
# Foundation; either version 2 of the License, or (at your option) any later |
|---|
| 10 |
# version. |
|---|
| 11 |
# |
|---|
| 12 |
# This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 13 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|---|
| 14 |
# FOR A PARTICULAR PURPOSE. See the file COPYING for more details. |
|---|
| 15 |
# |
|---|
| 16 |
# You should have received a copy of the GNU General Public License along with |
|---|
| 17 |
# this program; if not, write to the Free Software Foundation, Inc., 51 |
|---|
| 18 |
# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|---|
| 19 |
|
|---|
| 20 |
""" |
|---|
| 21 |
Priority queueing of tasks to one or more threaded or asynchronous workers. |
|---|
| 22 |
""" |
|---|
| 23 |
|
|---|
| 24 |
from workers import * |
|---|
| 25 |
from base import TaskQueue |
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
class ThreadQueue(TaskQueue): |
|---|
| 29 |
""" |
|---|
| 30 |
I am a task queue for dispatching arbitrary callables to be run by workers |
|---|
| 31 |
from a pool of I{N} worker threads, the number I{N} being specified as the |
|---|
| 32 |
sole argument of my constructor. |
|---|
| 33 |
""" |
|---|
| 34 |
def __init__(self, N, **kw): |
|---|
| 35 |
TaskQueue.__init__(self, **kw) |
|---|
| 36 |
for null in xrange(N): |
|---|
| 37 |
worker = ThreadWorker() |
|---|
| 38 |
self.attachWorker(worker) |
|---|