summaryrefslogtreecommitdiff
path: root/portato/waiting_queue.py
blob: 32839d32b8fe8ba0a2c93834a2ffe66d6c0cf76a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# -*- coding: utf-8 -*-
#
# File: portato/waiting_queue.py
# This file is part of the Portato-Project, a graphical portage-frontend.
#
# Copyright (C) 2007 René 'Necoro' Neumann
# This is free software.  You may redistribute copies of it under the terms of
# the GNU General Public License version 2.
# There is NO WARRANTY, to the extent permitted by law.
#
# Written by René 'Necoro' Neumann <necoro@necoro.net>

from __future__ import absolute_import

from threading import Thread, Event
from Queue import Queue

class WaitingQueue (Queue):

	def __init__ (self, setTrue = True, threadClass = Thread):
		if not issubclass(threadClass, Thread):
			raise ValueError, "Only subclasses of threading.Thread are allowed."
		
		Queue.__init__(self)
		self.event = Event()
		self.counter = 0
		self.threadClass = threadClass

		if setTrue:
			self.event.set() # true at the beginning

		waitingThread = self.threadClass(name = "Waiting-Queue-Thread", target = self.runThread)
		waitingThread.setDaemon(True)
		waitingThread.start()

	def put (self, method, *args, **kwargs):
		self.counter += 1;
		
		if "caller" in kwargs:
			name = "Waiting Thread #%d (called by:%s)" % (self.counter, kwargs["caller"])
			del kwargs["caller"]
		else:
			name = "Waiting Thread #%d" % self.counter

		t = self.threadClass(name = name, target = method, args = args, kwargs = kwargs)
		t.setDaemon(True)
		Queue.put(self, t, False)

	def runThread (self):
		while True:
			self.event.wait()
			t = self.get(True)
			self.event.clear()
			t.run()

	def next (self):
		self.event.set()

	def clear (self):
		self.mutex.acquire()
		self.queue.clear()
		self.mutex.release()
		self.event.set()
href='/others/pass.git/commit/src/password-store.sh?id=36a5583120ad8a6f939a8971284424d580c48ab2&follow=1'>git: use secure tmp directoryJason A. Donenfeld1-4/+11 2014-05-10configure git to decrypt gpg files automaticallySamuel Le Thiec1-0/+5 - usefull for git commands showing diff, e.g.: pass git log -p - from what I can see, not 'cleartext' temporary files are created 2014-05-08completion: add new generate flagsJason A. Donenfeld3-2/+7 2014-05-08inplace: mutually exclusive with forceJason A. Donenfeld2-3/+3 2014-05-08usage: tab to spacesJason A. Donenfeld1-1/+1 2014-05-08generate: use nice ansi colors instead.Jason A. Donenfeld1-3/+2 Revert "Mute git-commit messages to make pass insert readable" This reverts commit f30ce6374d554e704162d5fa8e49acd9c6fd0ecc. I decided I like the git output. Instead highlight generated passwords using nice terminal output instead. 2014-05-08zsh: posix compatible sed fix for zsh-completionJason A. Donenfeld1-1/+1 This reverts commit 56381287a16792b4c6410f07db68e02f3574c213, and further fixes things. 2014-05-07Implement interactive init functionSvend Sorensen1-0/+8 2014-05-07Implement interactive rename functionSvend Sorensen1-0/+7 2014-05-07Reorder interactive function to match order of helper functionsSvend Sorensen1-13/+13 2014-05-07Make edit helper function name consistent with other helpersSvend Sorensen1-1/+1 2014-05-07Factor out password completing-read functionSvend Sorensen1-4/+8 2014-05-07Add dash to Package-RequiresSvend Sorensen1-1/+1 2014-05-06Force sane sort order.Jason A. Donenfeld1-2/+2 2014-05-06generate: add --in-place optionJason A. Donenfeld4-9/+33