예제 #1
0
    def setUp(self):
        EventLoopTest.setUp(self)

        self.responder = TestSubprocessResponder()
        self.subprocess = subprocessmanager.SubprocessManager(
            TestMessage, self.responder, TestSubprocessHandler)
        self.subprocess.start()
        self._wait_for_subprocess_ready()
예제 #2
0
        msg, callback, errback = self.tasks_in_progress.pop(reply.task_id)
        if isinstance(reply.result, Exception):
            errback(reply.result)
        else:
            callback(reply.result)

    def run_pending_tasks(self):
        """Rerun all tasks in the queue."""
        for msg, callback, errback in self.tasks_in_progress.values():
            msg.send_to_process()


_task_queue = TaskQueue()

# Manage subprocess
_subprocess_manager = subprocessmanager.SubprocessManager(
    TaskMessage, WorkerProcessResponder(), WorkerProcessHandler)


def startup():
    """Startup the worker process."""
    _subprocess_manager.start()


def shutdown():
    """Shutdown the worker process."""
    _subprocess_manager.shutdown()


# API for sending tasks
def run_feedparser(html, callback, errback):
    """Run feedparser on a chunk of html."""