def _create_job(self, *args, **kwargs): cb = Callback._get_callback(self) job = ThreadInProgress(cb, *args, **kwargs) job.priority = self.priority if not _threads.has_key(self._thread): _threads[self._thread] = _JobServer(self._thread) server = _threads[self._thread] server.add(job) # Hook the aborted signal for the ThreadInProgress to stop the thread # callback. self._setup_abort(server, job) return job
def _create_thread(self, *args, **kwargs): """ Create and start the thread. """ cb = Callback._get_callback(self) async = ThreadInProgress(cb, *args, **kwargs) # create thread and setDaemon t = threading.Thread(target=async) t.setDaemon(not self._wait_on_exit) # connect thread.join to the InProgress join = lambda *args, **kwargs: t.join() # Hook the aborted signal for the ThreadInProgress to stop the thread # callback. self._setup_abort(t, async) # XXX: this was in the original abort code but I don't think it's necessary. # If I'm wrong, uncomment and explain why it's needed. #async.signals['abort'].connect(lambda: async.exception.disconnect(join)) async.connect_both(join, join) # start the thread t.start() return async