Created
November 20, 2018 23:00
-
-
Save Hermann-SW/6cfd38703614b0f6b4f5e19dcbf4e8a9 to your computer and use it in GitHub Desktop.
65 concurrent uasyncio worker threads on 28KB free RAM ESP-01s module MicroPython
This file contains 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 uasyncio as asyncio | |
N = 65 | |
loop = asyncio.get_event_loop(runq_len = N+1) | |
def collatz(x): | |
yield x | |
while x!=1: | |
x = 3*x+1 if x%2==1 else x//2 | |
yield x | |
async def worker(x): | |
global N | |
c = 0 | |
for k in collatz(x): | |
c = c+1 | |
await asyncio.sleep(0) | |
print(x, c-1) | |
N = N-1 | |
class Waiting(): | |
def __await__(self): | |
global N | |
while N>0: yield from asyncio.sleep(1) | |
__iter__ = __await__ # issue 2678 | |
async def killer(): | |
await Waiting() | |
trash = [ loop.create_task(worker(N-x)) for x in range(N) ] | |
loop.run_until_complete( killer() ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment