本文整理汇总了Python中threading.Condition类的典型用法代码示例。如果您正苦于以下问题:Python Condition类的具体用法?Python Condition怎么用?Python Condition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Condition类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: TestBackend
class TestBackend(Backend):
def __init__(self, queue):
self.lock = Condition()
queue._set_backend(self)
# Statistics
self.notifies = 0
def start(self):
pass
def stop(self):
pass
def start_feedback(self):
pass
def queue_lock(self):
return self.lock
def queue_notify(self):
self.notifies += 1
self.lock.notify_all()
def sleep(self):
pass
开发者ID:bbits,项目名称:apns-worker,代码行数:27,代码来源:test_queue.py
示例2: __init__
def __init__(self):
'''Init.'''
gobject.GObject.__init__(self)
# set condition lock.
self.__condition = Condition()
# set datebase operation lock.
self.__db_operation_lock = Condition()
# songs
self.__hiddens = set()
self.__song_types_capability = {}
self.__songs = {}
self.__song_types = []
self.__songs_by_type = {}
# playlist
self.__playlists = {}
self.__playlist_types = []
# init constant
self.__is_loaded = False
self.__force_check = False
self.__save_song_type = ["local", "cue", "unknown"]
self.__dirty = False
# Init queued signal.
self.__reset_queued_signal()
开发者ID:WilliamRen,项目名称:deepin-music-player,代码行数:29,代码来源:library.py
示例3: SimpleBlockingQueue
class SimpleBlockingQueue(object):
def __init__(self):
self.items = deque()
self.condition = Condition()
self.interrupted = False
def put(self, item):
with self.condition:
self.items.pushleft(item)
def take(self, block=False):
with self.condition:
if block:
while not self.items:
self.condition.wait()
if self.interrupted:
self.interrupted = False
return None
elif not self.items:
return None
return self.items.popright()
def interrupt(self):
with self.condition:
self.interrupted = True
self.condition.notifyAll()
开发者ID:RecruiterBill,项目名称:zephyr-mobile,代码行数:27,代码来源:test_zephyr.py
示例4: Future
class Future(object):
def __init__(self, func, *args, **kwargs):
self.__done = False
self.__result = None
self.__cond = Condition()
self.__func = func
self.__args = args
self.__kwargs = kwargs
self.__except = None
def __call__(self):
with self.__cond:
try:
self.__result = self.__func(*self.__args, **self.__kwargs)
except:
self.__result = None
self.__except = sys.exc_info()
self.__done = True
self.__cond.notify()
def result(self):
with self.__cond:
while not self.__done:
self.__cond.wait()
if self.__except:
exc = self.__except
reraise(exc[0], exc[1], exc[2])
result = self.__result
return copy.deepcopy(result)
开发者ID:sevensky,项目名称:MyST3Data,代码行数:29,代码来源:Common.py
示例5: SendBuffer
class SendBuffer(object):
def __init__(self, max_size):
self.size = 0
self.frontbuffer = ''
self.full = Condition()
self.backbuffer = StringIO()
self.max_size = max_size
def __len__(self):
return len(self.frontbuffer) + self.size
def write(self, data):
dlen = len(data)
with self.full:
while self.size + dlen > self.max_size and dlen < self.max_size:
# if a single write is bigger than the buffer, swallow hard.
# No amount of waitng will make it fit.
self.full.wait()
self.backbuffer.write(data)
self.size += dlen
def to_sock(self, sock):
if not self.frontbuffer:
with self.full:
buf, self.backbuffer = self.backbuffer, StringIO()
self.size = 0
self.full.notify_all()
self.frontbuffer = buf.getvalue()
written = sock.send(self.frontbuffer)
self.frontbuffer = self.frontbuffer[written:]
开发者ID:pepijndevos,项目名称:pypredis,代码行数:32,代码来源:sendbuffer.py
示例6: __init__
def __init__(self, client):
self.prefix = "auau:"
self.mc = client
self.random = Random()
self.random.seed(os.urandom(128))
self.random.jumpahead(os.getpid())
# thread exit flag
self.exit_flag = [False]
from threading import Thread
from threading import Condition
# asynchronous deflation thread
self.def_cv = Condition()
self.def_que = []
self.def_thread = Thread(
target=lambda: self.async_work(self.def_cv, self.def_que, self.exit_flag, lambda x: self.deflate(x))
)
self.def_thread.setDaemon(True)
self.def_thread.start()
# asynchronous deletion thread
self.del_cv = Condition()
self.del_que = []
self.del_thread = Thread(
target=lambda: self.async_work(self.del_cv, self.del_que, self.exit_flag, lambda x: self.mc.delete(x))
)
self.del_thread.setDaemon(True)
self.del_thread.start()
开发者ID:kumagi,项目名称:kvtx2,代码行数:30,代码来源:__init__.py
示例7: IOManager
class IOManager(Thread):
def __init__(self,so):
Thread.__init__(self)
self.mutexIO = Condition()
self.listIO = []
self.handlerIO = so.handlerIO
def process(self):
for irq in self.listIO:
print("Ejecuto IOManager")
self.handlerIO.handle(irq)
self.removeIOFromListIO()
def run(self):
while(True):
with self.mutexIO:
self.mutexIO.wait()
self.process()
def removeIOFromListIO(self):
for reqIO in self.listIO:
self.listIO.remove(reqIO)
def add(self,iOReq):
self.listIO.append(iOReq)
开发者ID:Bequita,项目名称:EmuladorS.O.,代码行数:26,代码来源:IOManager.py
示例8: Worker
class Worker(Thread):
def __init__(self):
Thread.__init__(self)
self.lock = Lock()
self.cond = Condition(self.lock)
self.stopped = False
self.queue = []
def run(self):
while True:
job = None
with self.cond:
if self.stopped:
return
if not self.queue:
self.cond.wait()
else:
job, params = self.queue.pop(0)
if not job:
continue
self.execute(job, params)
def execute(self, job, params):
try:
func, args = job(*params)
# The async function may decide to NOT update
# the UI:
if func:
gobject.idle_add(func, *args)
except Exception, e:
print "Warning:", e
开发者ID:pablojorge,项目名称:gtk-viewer,代码行数:31,代码来源:threads.py
示例9: __init__
def __init__(self, num_photos=10, sources=[], pool_dir=cache_dir):
Thread.__init__(self)
self.num_photos = num_photos
self.sources = sources
self.dir = pool_dir
# Make sure cache dir exists
if not os.path.exists(self.dir):
os.mkdir(self.dir)
# Clean cache directory
self.clean_cache()
# Load cached photos
self.photos = os.listdir(self.dir)
# Delete queue
self.trash = []
# Condition when a new photo is added
self.added = Condition()
# Condition when a photo is removed
self.removed = Condition()
# Event for stopping the pool
self._stop = Event()
开发者ID:joh,项目名称:Flickrsaver,代码行数:28,代码来源:flickrsaver.py
示例10: __init__
def __init__(self, algorithm, interpreter, change_listener, debug=False,
progress_listener=None):
if not isinstance(algorithm, Algorithm):
raise TypeError('%r is not a matching algorithm object' %
algorithm)
self.current_location = None
self.previous_location = None
self._debug_enabled = debug
self._running = False
self._within_piece = False
self._startup_condition = Condition()
self._piece_control = Condition()
self._playing_piece = False
self._history = HistoryQueue()
self.intervals = None
self._incoming_notes = None
self.interpreter = interpreter
self.change_listener = change_listener
self.progress_listener = progress_listener
algorithm.assign_matcher(self)
self._algorithm = algorithm
self._thread = None
self._stopping = False
开发者ID:enaeseth,项目名称:musicstand,代码行数:28,代码来源:matcher.py
示例11: __init__
def __init__(self, number_threads):
self.pool_lock = Lock()
self.connection_available = Condition(self.pool_lock)
self.request_available = Condition(self.pool_lock)
self.connection_pool = []
self.number_connections = 0
self.max_connections = number_threads
开发者ID:Gerst20051,项目名称:Python,代码行数:7,代码来源:smtp_server.py
示例12: __init__
def __init__(self):
self.lock = Lock()
self.toWrite = Condition(self.lock)
self.toBackup = Condition(self.lock)
self.isWriting = False
self.isBackup = False
self.emailNum = 1
开发者ID:ninefu,项目名称:Filesystem-with-SMTP-Mailsever,代码行数:7,代码来源:MailServer.py
示例13: __init__
def __init__(self):
# TODO
self.carsCrossingNorth = 0
self.carsCrossingSouth = 0
self.cvLock = Lock()
self.southQ = Condition(self.cvLock)
self.northQ = Condition(self.cvLock)
开发者ID:johncurcio,项目名称:cs4410,代码行数:7,代码来源:q04-bridge-mon.py
示例14: __init__
class Future:
def __init__(self, correlation_id, request_type=None):
self.correlation_id = correlation_id
self._result = None
self._condition = Condition()
self._request_type = request_type
def done(self):
return self._result is not None
def result(self, timeout=None):
with self._condition:
if self._result is None:
if not self._condition.wait(timeout):
message_type = validator_pb2.Message.MessageType.Name(
self._request_type) if self._request_type else None
raise FutureTimeoutError(
'Future timed out waiting for response to {}'.format(
message_type))
return self._result
def set_result(self, result):
with self._condition:
self._result = result
self._condition.notify()
开发者ID:cianx,项目名称:sawtooth-core,代码行数:25,代码来源:future.py
示例15: Presponse
class Presponse(PktHandler):
def __init__(self):
self.ping_response_wait = Condition()
'''
To wait for a ping response, do the following:{
start = time.time()
with Presponse.ping_response_wait:
Presponse.ping_response_wait.wait(5) # Standard timeout in PING latency is 5.
end = time.time()
}
(end - start) is the ping latency.
'''
def handle(self, packet_map):
with self.ping_response_wait:
self.ping_response_wait.notify_all()
return None
def getproperties(self):
return {
'DisplayName':'Ping-Response Notifier',
'CodeName':'PRESPONSE_NOTIFY',
'PacketType':'PRESPONSE',
'Version':0.01
}
开发者ID:broad-well,项目名称:lightweight-iot-protocol,代码行数:25,代码来源:StandardModules.py
示例16: BackUpThread
class BackUpThread (threading.Thread):
def __init__(self):
threading.Thread.__init__ ( self )
self.srcfile = "D:\study\operating system prac\CS4410\mp3\mp3\src\mail.txt"
self.destfile = "D:\study\operating system prac\CS4410\mp3\mp3\src\\backup.txt"
self.mutex = Lock()
self.cv = Condition(self.mutex)
self.msgCount = 0
def run(self):
with self.mutex:
while True:
# TODO: BUG here.
while self.msgCount != 32:
self.cv.wait()
print "Backing up the mail file."
# TODO: copy only the new part.
# desthandle = open(self.destfile, "r")
# desthandle.seek(0, 2)
# offset = desthandle.tell()
shutil.copyfile(self.srcfile, self.destfile)
self.msgCount = 0
def newMsg(self):
with self.mutex:
self.msgCount += 1
if self.msgCount == 32:
self.cv.notifyAll()
开发者ID:Yashg19,项目名称:operatingsystemslfs,代码行数:30,代码来源:BackUpThread.py
示例17: __init__
def __init__(self, node_id, data):
"""
Constructor.
@type node_id: Integer
@param node_id: the unique id of this node; between 0 and N-1
@type data: List of Integer
@param data: a list containing this node's data
"""
self.node_id = node_id
self.data = data
# temporary buffer for needed for scatter
self.copy = data[:]
self.lock_copy = Lock()
self.nodes = None
self.lock_data = Lock()
# list of threads (in this case 16 fo each node)
self.thread_list = []
# list with tasks that need to be computed
self.thread_pool = []
self.mutex = Lock()
# condition used for put and get
self.condition = Condition(self.mutex)
# condition needed for checking if there are
# still tasks that need o be solved
self.all_tasks_done = Condition(self.mutex)
# number of unfinished tasks
self.unfinished_tasks = 0
# start the 16 threads
for i in range(16):
th = Worker(self, i)
self.thread_list.append(th)
th.start()
开发者ID:ClaudiaRogoz,项目名称:Cluster-Simulation,代码行数:34,代码来源:node.py
示例18: __init__
def __init__(self, cache_dir, map_desc, db_schema, is_concurrency=True):
self.__map_desc = map_desc
self.__db_path = os.path.join(cache_dir, map_desc.map_id + ".mbtiles")
self.__conn = None
#configs
self.__db_schema = db_schema
self.__has_timestamp = True
self.__is_concurrency = is_concurrency
if is_concurrency:
self.__surrogate = None #the thread do All DB operations, due to sqlite3 requiring only the same thread.
self.__is_closed = False
#concurrency get/put
self.__sql_queue = []
self.__sql_queue_lock = Lock()
self.__sql_queue_cv = Condition(self.__sql_queue_lock)
self.__get_lock = Lock() #block the 'get' action
self.__get_respose = None #the pair (data, exception)
self.__get_respose_lock = Lock()
self.__get_respose_cv = Condition(self.__get_respose_lock)
开发者ID:dayanuyim,项目名称:GisEditor,代码行数:26,代码来源:tile.py
示例19: ResourcePool
class ResourcePool(object):
def __init__(self, initial_value):
super(ResourcePool, self).__init__()
self.condition = Condition()
self.value = initial_value
def acquire(self, amount):
with self.condition:
while amount > self.value:
self.condition.wait()
self.value -= amount
self.__validate()
def release(self, amount):
with self.condition:
self.value += amount
self.__validate()
self.condition.notifyAll()
def __validate(self):
assert 0 <= self.value
def __str__(self):
return str(self.value)
def __repr__(self):
return "ResourcePool(%i)" % self.value
@contextmanager
def acquisitionOf(self, amount):
self.acquire(amount)
try:
yield
finally:
self.release(amount)
开发者ID:common-workflow-language,项目名称:toil,代码行数:35,代码来源:singleMachine.py
示例20: __init__
def __init__(self):
self.nwasherWaiting = 0 # number of sims waiting for washing hands
self.nwasherUsing = 0 # number of sims washing hands right now
self.toiletBusy = 0 # is toilet busy right now ?
self.bathroomLock = Lock();
self.toiletLine = Condition(self.bathroomLock)
self.washerLine = Condition(self.bathroomLock)
开发者ID:kathomas921,项目名称:courses,代码行数:7,代码来源:q03.py
注:本文中的threading.Condition类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论