This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import asyncio | |
| import contextvars | |
| import uvloop | |
| from types import SimpleNamespace | |
| asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) | |
| N = 100000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import asyncio | |
| import contextvars | |
| import uvloop | |
| from types import SimpleNamespace | |
| asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) | |
| trace_context = contextvars.ContextVar('trace_context') | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import aioredis | |
| import asyncio | |
| import json | |
| from aiohttp import web | |
| tasks = {} | |
| task_id = 0 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import asyncio | |
| import sys | |
| async def foo(): | |
| pass | |
| async def test(): | |
| t = asyncio.tasks.create_task(foo()) | |
| print(sys.getsizeof(t)) | |
| print(id(t)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Python 3.7.0b1 (v3.7.0b1:9561d7f501, Jan 30 2018, 19:10:11) | |
| [Clang 6.0 (clang-600.0.57)] on darwin | |
| Type "help", "copyright", "credits" or "license" for more information. | |
| >>> import contextvars | |
| >>> foo = contextvars.ContextVar("foo") | |
| >>> foo.set("a") | |
| <Token var=<ContextVar name='foo' at 0x10ccbe2b0> at 0x10ccc36c0> | |
| >>> bar = contextvars.ContextVar("bar", default="b") | |
| >>> list(contextvars.copy_context().keys()) | |
| [<ContextVar name='foo' at 0x10ccbe2b0>] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from timeit import timeit | |
| class Object: | |
| def __init__(self, x): | |
| self.x = x | |
| class Rule: | |
| def __init__(self, valid_values, valid_values2): | |
| self.valid_values = valid_values | |
| self.valid_values2 = valid_values2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async def request_start(session, trace_context, method, host, port, headers): | |
| trace_context.start = loop.time() | |
| headers['X-Request-id'] = 'request_id' | |
| async def request_stop(session, trace_context, response): | |
| print("request type {}".format(trace_context.query)) | |
| print("request finsihed with {} status code".format(response.status_code)) | |
| print("request took {}".format(loop.time() - trace_context.start)) | |
| async def request_exception(session, trace_context, exc): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MetricsClient(ClientSession): | |
| def __init__(self, metric_name, region, **kwargs): | |
| self(MetricsClient, self).__init__( | |
| self, | |
| *args, | |
| request_tracing=True, | |
| request_tracing_ctx=dict | |
| **kwargs) | |
| self.metric_name = metric_name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from time import time | |
| from blinker import signal | |
| N = 1000000 | |
| test = signal('test') | |
| start = time() | |
| for i in range(N): | |
| test.send() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import asyncio | |
| from aiohttp.signals import Signal | |
| from unittest.mock import Mock | |
| signal = Signal(Mock()) | |
| async def run_signal(loop, signals): | |
| start = loop.time() | |
| for i in range(signals): |