text
stringlengths 0
828
|
|---|
""""""
|
This method is the actual implementation of the job. By default, it calls
|
the target function specified in the #Job constructor.
|
""""""
|
if self.__target is not None:
|
return self.__target(self, *self.__args, **self.__kwargs)
|
raise NotImplementedError"
|
447,"def factory(start_immediately=True):
|
""""""
|
This is a decorator function that creates new `Job`s with the wrapped
|
function as the target.
|
# Example
|
```python
|
@Job.factory()
|
def some_longish_function(job, seconds):
|
time.sleep(seconds)
|
return 42
|
job = some_longish_function(2)
|
print(job.wait())
|
```
|
# Arguments
|
start_immediately (bool): #True if the factory should call #Job.start()
|
immediately, #False if it should return the job in pending state.
|
""""""
|
def decorator(func):
|
def wrapper(*args, **kwargs):
|
job = Job(task=lambda j: func(j, *args, **kwargs))
|
if start_immediately:
|
job.start()
|
return job
|
return wrapper
|
return decorator"
|
448,"def start(self):
|
""""""
|
Starts the #ThreadPool. Must be ended with #stop(). Use the context-manager
|
interface to ensure starting and the #ThreadPool.
|
""""""
|
if self.__running:
|
raise RuntimeError('ThreadPool already running')
|
[t.start() for t in self.__threads]
|
self.__running = True"
|
449,"def current_jobs(self):
|
""""""
|
Returns a snapshot of the Jobs that are currently being processed by the
|
ThreadPool. These jobs can not be found in the #pending_jobs() list.
|
""""""
|
jobs = []
|
with synchronized(self.__queue):
|
for worker in self.__threads:
|
with synchronized(worker):
|
if worker.current:
|
jobs.append(worker.current)
|
return jobs"
|
450,"def clear(self):
|
""""""
|
Removes all pending Jobs from the queue and return them in a list. This
|
method does **no**t call #Job.cancel() on any of the jobs. If you want
|
that, use #cancel_all() or call it manually.
|
""""""
|
with synchronized(self.__queue):
|
jobs = self.__queue.snapshot()
|
self.__queue.clear()
|
return jobs"
|
451,"def cancel_all(self, cancel_current=True):
|
""""""
|
Similar to #clear(), but this function also calls #Job.cancel() on all
|
jobs. Also, it **includes** all jobs that are currently being executed if
|
*cancel_current* is True.
|
# Arguments
|
cancel_current (bool): Also cancel currently running jobs and include them
|
in the returned list of jobs.
|
# Returns
|
list: A list of the #Job#s that were canceled.
|
""""""
|
with synchronized(self.__queue):
|
jobs = self.clear()
|
if cancel_current:
|
jobs.extend(self.current_jobs())
|
[j.cancel() for j in jobs]
|
return jobs"
|
452,"def submit(self, target=None, task=None, args=(), kwargs=None, front=False,
|
dispose_inputs=None):
|
""""""
|
Submit a new #Job to the ThreadPool.
|
# Arguments
|
task (function, Job): Either a function that accepts a #Job, *args* and
|
*kwargs* or a #Job object that is in #~Job.PENDING state.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.