示例#1
0
 def check_if_assignation_cancelled(self, task: Task):
     if task.cancelled():
         console.log(
             f"[yellow] Assignation {task} Cancelled and is now Done")
     elif task.exception():
         console.log(
             f"[red] Assignation {task} Failed with {str(task.exception())}"
         )
     elif task.done():
         console.log(
             f"[green] Assignation {task} Succeeded and is now Done")
 async def test_create_response(self):
     task = Task.current_task(loop=self.loop)
     task.session = {}
     task.endpoint_desc = {}
     task.request_params = {}
     response = self.service_client.create_response(method='get', url=URL("http://test.com"),
                                                    writer=None, continue100=False, timer=None,
                                                    request_info=RequestInfo(URL("http://test.com"), 'get', []),
                                                    auto_decompress=False,
                                                    traces=[], loop=self.loop, session=self.service_client.session)
     self.assertIsInstance(response, ObjectWrapper)
def mailer(event_loop, unused_tcp_port, request, recipients):
    auth_mechanism, fail_on = request.param
    callback = partial(MockSMTPServer.connected, auth_mechanism=auth_mechanism,
                       fail_on=fail_on, recipients=recipients)
    task = start_server(callback, '127.0.0.1', unused_tcp_port)
    server = event_loop.run_until_complete(task)
    mailer = SMTPMailer(host='127.0.0.1', port=unused_tcp_port, username='******',
                        password='******', timeout=1)
    event_loop.run_until_complete(mailer.start(Context()))
    yield mailer
    server.close()
    tasks = Task.all_tasks(event_loop)
    event_loop.run_until_complete(gather(*tasks))
示例#4
0
文件: statsd.py 项目: mahdiyari/jussi
async def send_stats(request: HTTPRequest, response: HTTPResponse) -> None:
    # pylint: disable=bare-except
    try:
        statsd_client = getattr(request.app.config, 'statsd_client', None)
        if not statsd_client:
            return
        if request.is_single_jrpc:
            statsd_client.from_timings(request.timings)
            statsd_client.from_timings(request.jsonrpc.timings)
            statsd_client.decr('jrpc.inflight')
            statsd_client.gauge('tasks', len(Task.all_tasks()))
            statsd_client._sendbatch()
        elif request.is_batch_jrpc:
            statsd_client.from_timings(request.timings)
            for r in request.jsonrpc:
                statsd_client.from_timings(r.timings)
                statsd_client.decr('jrpc.inflight')
            statsd_client._sendbatch()
    except BaseException as e:
        logger.warning('send_stats', e=e)
示例#5
0
 def current_task():
     return Task.current_task()
示例#6
0
 async def receive_data(q: asyncio.Queue, task: Task):
     while True:
         data = await q.get()
         print(data)
         task.cancel()
         break
示例#7
0
 def test_identfy_current_task(self):
     self.assertEqual(id(Task.current_task()), identify_future())
示例#8
0
 def test_identfy_current_task(self):
     self.assertEqual(id(Task.current_task()), identify_future())