text
stringlengths 0
828
|
|---|
target (function): A function object that accepts *args* and *kwargs*.
|
Only if *task* is not specified.
|
args (list, tuple): A list of arguments to be passed to *job*, if it is
|
a function.
|
kwargs (dict): A dictionary to be passed as keyword arguments to *job*,
|
if it is a function.
|
front (bool): If #True, the job will be inserted in the front of the queue.
|
# Returns
|
Job: The job that was added to the queue.
|
# Raises
|
TypeError: If a #Job object was passed but *args* or *kwargs* are non-empty.
|
RuntimeError: If the ThreadPool is not running (ie. if it was shut down).
|
""""""
|
if not self.__running:
|
raise RuntimeError(""ThreadPool ain't running"")
|
if dispose_inputs is None:
|
dispose_inputs = self.dispose_inputs
|
if isinstance(task, Job):
|
if args or kwargs:
|
raise TypeError('can not provide additional arguments for Job')
|
if task.state != Job.PENDING:
|
raise RuntimeError('job is not pending')
|
job = task
|
elif task is not None:
|
if kwargs is None:
|
kwargs = {}
|
job = Job(task=task, args=args, kwargs=kwargs, dispose_inputs=dispose_inputs)
|
elif target is not None:
|
if kwargs is None:
|
kwargs = {}
|
job = Job(target=target, args=args, kwargs=kwargs, dispose_inputs=dispose_inputs)
|
else:
|
raise TypeError('expected Job or callable')
|
job.print_exc = self.print_exc
|
if front:
|
self.__queue.appendleft(job)
|
else:
|
self.__queue.append(job)
|
return job"
|
453,"def wait(self, timeout=None):
|
""""""
|
Block until all jobs in the ThreadPool are finished. Beware that this can
|
make the program run into a deadlock if another thread adds new jobs to the
|
pool!
|
# Raises
|
Timeout: If the timeout is exceeded.
|
""""""
|
if not self.__running:
|
raise RuntimeError(""ThreadPool ain't running"")
|
self.__queue.wait(timeout)"
|
454,"def shutdown(self, wait=True):
|
""""""
|
Shut down the ThreadPool.
|
# Arguments
|
wait (bool): If #True, wait until all worker threads end. Note that pending
|
jobs are still executed. If you want to cancel any pending jobs, use the
|
#clear() or #cancel_all() methods.
|
""""""
|
if self.__running:
|
# Add a Non-entry for every worker thread we have.
|
for thread in self.__threads:
|
assert thread.isAlive()
|
self.__queue.append(None)
|
self.__running = False
|
if wait:
|
self.__queue.wait()
|
for thread in self.__threads:
|
thread.join()"
|
455,"def submit_multiple(self, functions, target=False, task=False):
|
""""""
|
Submits a #Job for each element in *function* and returns a #JobCollection.
|
""""""
|
if target or not task:
|
return JobCollection([self.submit(target=func) for func in functions])
|
else:
|
return JobCollection([self.submit(task=func) for func in functions])"
|
456,"def new_event_type(self, name, mergeable=False):
|
''' Declare a new event. May overwrite an existing entry. '''
|
self.event_types[name] = self.EventType(name, mergeable)"
|
457,"def add_event(self, name, data=None):
|
'''
|
Add an event of type *name* to the queue. May raise a
|
`ValueError` if the event type is mergeable and *data* is not None
|
or if *name* is not a declared event type (in strict mode).
|
'''
|
try:
|
mergeable = self.event_types[name].mergeable
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.