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
#!/usr/bin/python3 | |
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 |
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 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): | |
return self._portal.run(self._queue.trio_get) |
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 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 """ |