How to view exceptions when using asyncio and executor pools?

How can I get exceptions from different processes to spit out stdout when using executor pools with asyncio?

At the moment, all exceptions are airborne and I can only partially clear what happens when I kill the script via ctrl-c ....

here's some code:

import lib.myFunctions
import asyncio
import oandapy


fmc = lib.myFunctions.FmcMixin()


def meatAndPotatoes(currency_pair=sys.argv[1],
    time_compression=sys.argv[2],sleep_time=sys.argv[3]):
    while True:
        try:
            something = oanda.get_history()
            if (something):
                print("niceeee")
            else:
                print("ok cool")
        except:
            sleep(sleep_time)


if __name__ == "__main__":
    executor = ProcessPoolExecutor(2)
    loop = asyncio.get_event_loop()
    asyncio.async(loop.run_in_executor(executor, meatAndPotatoes))
    scriptName = str(sys.argv[1] + "/" + sys.argv[2] + "/")
    asyncio.async(loop.run_in_executor(executor, fmc.heartbeatFunction(scriptName)))
    loop.run_forever()

      

When meatAndPotatoes has problems, I don't see any errors before ctrl-c, just like fmc.heartbeatFunction ....

+3


source to share





All Articles