Skip to content

Instantly share code, notes, and snippets.

smurfix /
Last active February 14, 2024 18:15
Trio: results-gathering nursery wrapper
import trio
import outcome
from contextlib import asynccontextmanager
class StreamResultsNursery:
def __init__(self, max_buffer_size=1):
self.nursery = trio.open_nursery()
self.max_buffer_size = max_buffer_size
class UniversalQueue:
def __init__(self, *args, **kwargs):
self._queue = trio.Queue(*args, **kwargs)
self._portal = trio.BlockingTrioPortal()
async def trio_get(self):
return await self._queue.trio_get()
def thread_get(self):
mcleonard /
Last active February 22, 2024 12:30
A vector class in pure python.
import math
class Vector(object):
def __init__(self, *args):
""" Create a vector, example: v = Vector(1,2) """
if len(args)==0: self.values = (0,0)
else: self.values = args
def norm(self):
""" Returns the norm (length, magnitude) of the vector """