| 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 from queue import Queue
24
25 LOW = 0
26 MEDIUM = 10
27 HIGH = 100
28
29 PRIORITY = {
30 'LOW': LOW,
31 'MEDIUM': MEDIUM,
32 'HIGH': HIGH,
33 }
34 REVERSE_PRIORITY = dict((values, key) for key, values in PRIORITY.items())
35
36
37
39
41 """Initialize the queue representation"""
42 self.maxsize = maxsize
43 # ordered list of task, from the lowest to the highest priority
44 self.queue = []
45
47 """Put a new item in the queue"""
48 for i, task in enumerate(self.queue):
49 # equivalent task
50 if task == item:
51 # if new task has a higher priority, remove the one already
52 # queued so the new priority will be considered
53 if task < item:
54 item.merge(task)
55 del self.queue[i]
56 break
57 # else keep it so current order is kept
58 task.merge(item)
59 return
60 insort_left(self.queue, item)
61
65
68
77
101
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Wed Feb 19 13:32:28 2014 | http://epydoc.sourceforge.net |