| Home | Trees | Indices | Help |
|
|---|
|
|
1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
3 #
4 # This file is part of logilab-common.
5 #
6 # logilab-common is free software: you can redistribute it and/or modify it under
7 # the terms of the GNU Lesser General Public License as published by the Free
8 # Software Foundation, either version 2.1 of the License, or (at your option) any
9 # later version.
10 #
11 # logilab-common is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 # details.
15 #
16 # You should have received a copy of the GNU Lesser General Public License along
17 # with logilab-common. If not, see <http://www.gnu.org/licenses/>.
18 """Prioritized tasks queue"""
19
20 __docformat__ = "restructuredtext en"
21
22 from bisect import insort_left
23
24 from six.moves import queue
25
26 LOW = 0
27 MEDIUM = 10
28 HIGH = 100
29
30 PRIORITY = {
31 'LOW': LOW,
32 'MEDIUM': MEDIUM,
33 'HIGH': HIGH,
34 }
35 REVERSE_PRIORITY = dict((values, key) for key, values in PRIORITY.items())
36
37
38
40
42 """Initialize the queue representation"""
43 self.maxsize = maxsize
44 # ordered list of task, from the lowest to the highest priority
45 self.queue = []
46
48 """Put a new item in the queue"""
49 for i, task in enumerate(self.queue):
50 # equivalent task
51 if task == item:
52 # if new task has a higher priority, remove the one already
53 # queued so the new priority will be considered
54 if task < item:
55 item.merge(task)
56 del self.queue[i]
57 break
58 # else keep it so current order is kept
59 task.merge(item)
60 return
61 insort_left(self.queue, item)
62
66
69
71 """remove a specific task from the queue"""
72 # XXX acquire lock
73 for i, task in enumerate(self):
74 if task.id == tid:
75 self.queue.pop(i)
76 return
77 raise ValueError('not task of id %s in queue' % tid)
78
102
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Fri Dec 8 00:00:57 2017 | http://epydoc.sourceforge.net |