text
stringlengths 0
828
|
|---|
except KeyError:
|
if self.strict:
|
raise ValueError('unknown event type {0!r}'.format(name))
|
mergeable = False
|
if mergeable and data is not None:
|
raise ValueError('mergable event can not have data attached')
|
with self.lock:
|
if mergeable:
|
# Check if such an event already exists.
|
for ev in self.events:
|
if ev.type == name:
|
return
|
self.events.append(self.Event(name, data, time.clock()))"
|
458,"def pop_event(self):
|
'''
|
Pop the next queued event from the queue.
|
:raise ValueError: If there is no event queued.
|
'''
|
with self.lock:
|
if not self.events:
|
raise ValueError('no events queued')
|
return self.events.popleft()"
|
459,"def pop_events(self):
|
'''
|
Pop all events and return a `collections.deque` object. The
|
returned container can be empty. This method is preferred over
|
`pop_event()` as it is much faster as the lock has to be acquired
|
only once and also avoids running into an infinite loop during
|
event processing.
|
'''
|
with self.lock:
|
events = self.events
|
self.events = collections.deque()
|
return events"
|
460,"def clear(self):
|
""""""
|
Clears the queue. Note that calling #wait*( immediately after clear can
|
still block when tasks are currently being processed since this method can
|
only clear queued items.
|
""""""
|
self._tasks -= len(self._deque)
|
self._deque.clear()
|
notify_all(self)"
|
461,"def get(self, block=True, timeout=None, method='pop'):
|
""""""
|
If *block* is True, this method blocks until an element can be removed from
|
the deque with the specified *method*. If *block* is False, the function
|
will raise #Empty if no elements are available.
|
# Arguments
|
block (bool): #True to block and wait until an element becomes available,
|
#False otherwise.
|
timeout (number, None): The timeout in seconds to use when waiting for
|
an element (only with `block=True`).
|
method (str): The name of the method to use to remove an element from the
|
queue. Must be either `'pop'` or `'popleft'`.
|
# Raises
|
ValueError: If *method* has an invalid value.
|
Timeout: If the *timeout* is exceeded.
|
""""""
|
if method not in ('pop', 'popleft'):
|
raise ValueError('method must be ""pop"" or ""popleft"": {0!r}'.format(method))
|
t_start = time.clock()
|
while not self:
|
if not block:
|
raise self.Empty
|
if timeout is None:
|
wait(self)
|
else:
|
t_delta = time.clock() - t_start
|
if t_delta > timeout:
|
raise Timeout
|
wait(self, timeout - t_delta)
|
return getattr(self, method)()"
|
462,"def wait(self, timeout=None):
|
""""""
|
Waits until all tasks completed or *timeout* seconds passed.
|
# Raises
|
Timeout: If the *timeout* is exceeded.
|
""""""
|
t_start = time.clock()
|
if not wait_for_condition(self, lambda s: s._tasks == 0, timeout):
|
raise Timeout"
|
463,"def sleep(self):
|
""""""
|
Sleeps until the interval has passed since the last time this function was
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.