Skip to content

Instantly share code, notes, and snippets.

import pathlib
import sys
import tomllib
from collections.abc import Iterable
def main() -> None:
project = pathlib.Path("pyproject.toml")
module = tomllib.loads(project.read_text())["tool"]["mypy"]["overrides"][0][
"module"
import asyncio
import contextlib
async def child(sock):
try:
with contextlib.closing(sock):
await asyncio.sleep(2)
except Exception as e:
print(f"child task got error: {type(e)=} {e=}")
raise
import objgraph
import asyncio
READY = object()
import weakref
import asyncio
import gc
import logging
@graingert
graingert / demo.py
Created July 31, 2022 09:50
running trio in asyncio and getting the current task context
import asyncio
import collections.abc
import contextlib
import functools
import types
import httpx
import sniffio
import trio
import asyncio
import collections.abc
import contextlib
import functools
import types
import httpx
import sniffio
import trio
from twisted.internet import defer
import curio
import concurrent
class Interceptor:
def __init__(self, send, coro):
self._send = send
self._coro = coro
__all__ = 'run',
import functools
import asyncio
from asyncio import coroutines
from asyncio import events
from asyncio import tasks
import contextlib
@contextlib.contextmanager
@graingert
graingert / .gitignore
Last active July 28, 2022 10:11
twisted asyncio tests
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
import asyncio
import contextlib
class _AcknowledgeException:
def __init__(self, exception):
self.exception = exception
class _RecommendGeneratorExit(BaseException):
@graingert
graingert / agen_close.py
Last active July 22, 2022 10:20
closing an async_generator_asend does not throw GeneratorExit into the `await` statement
import types
def underline(text):
last_line = text.splitlines()[-1]
return text + "\n" + "^" * len(last_line)
@types.coroutine
def _async_yield(v):
return (yield v)