Exception Handling Question
pabloazurduy opened this issue · comments
Pablo Azurduy commented
Hi guys, I'm testing janus
queue to communicate an async
process with a sync one, the problem is that at some point the sync
process raises exceptions. how to handled them?
import asyncio
import janus
def threaded(sync_q):
for i in range(100):
raise Exception('Some custom Exception')
sync_q.put(i)
sync_q.join()
async def async_coro(async_q):
for i in range(100):
#should it be handeled here ?
val = await async_q.get()
assert val == i
async_q.task_done()
async def main():
queue = janus.Queue()
loop = asyncio.get_running_loop()
fut = loop.run_in_executor(None, threaded, queue.sync_q)
await async_coro(queue.async_q)
# try except block should be here ?
await fut
queue.close()
await queue.wait_closed()
asyncio.run(main())
Andrew Svetlov commented
Exception in the example just stops the producer (threaded()
function).
Nothing to do here in janus code.
The example should catch the error explicitly and maybe push it into the queue for future processing,