4 ms·
So it seems it would be able to have goless in python3 with this? The combination of spawning a function and using channels between them is great. Specially the
by Klasiaster 11y ago
So it seems it would be able to have goless in python3 with this? The combination of spawning a function and using channels between them is great. Specially the optional numeric argument of chan() where you can specify whether it's blocking or not, having a send buffer etc. Using an event loop with async/await could work nicely. Or also a version using real threads instead.
https://goless.readthedocs.org/en/latest/ https://goless.readthedocs.org/en/latest/
- Klasiaster 11y agoAh, found a https://github.com/stuglaser/pychan https://github.com/stuglaser/pychan which could be used with threads.
- Klasiaster 11y agoIt looks different than in Go, but works the same (when simulating a handshake for synchronous channels). #!/usr/bin/env python3.5 import asyncio async def give(start, end, c, k): for i in range(start, end): await c.put(i) await k.get() # sync send await c.put(None) # simulate closing of channel async def consume(c, k): while True: x = await c.get() await k.put(True) # sync recv if x is None: # channel closed return print(x) loop = asyncio.get_event_loop() c, k = asyncio.Queue(), asyncio.Queue() tasks = [asyncio.ensure_future(give(3, 7, c, k)), asyncio.ensure_future(consume(c, k))] try: loop.run_until_complete(asyncio.wait(tasks)) finally: loop.close()