如何在使用asyncio和executor池时查看异常?

时间:2015-07-10 23:58:13

标签: python python-3.x python-multithreading python-asyncio

当使用带有asyncio的执行程序池时,如何从stdout中获取不同进程的异常?

现在所有的异常都被困在以太中,当我通过ctrl-c杀死脚本时,我只能部分解决出错的问题。

这里有一些代码:

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()

当meatAndPotatoes出现问题时,我无法看到错误,直到ctrl-c,与fmc.heartbeatFunction相同....

0 个答案:

没有答案