IPython.parallel - can I write my own log into the engine logs?

拜拜、爱过 提交于 2020-01-07 02:44:08

问题


I'd like to be able to log outputs from the functions I pass to my engines in the relevant engine logs.

I.e.:

data = /* my list of data to operate on */
def fn(inval):
    import logging
    log = logging.getLogger()
    log.error('This is on the engine')
    // do stuff
    return result

calculated_data = []
for datum in data:
    calc = view.apply(fn, datum)
    calculated_data.append(calc)

I'd like to be able to see the log statements in the relevant engine log that operated on the specific task.


回答1:


You can grab the logger of the current app (i.e. the engine in this case) with:

from IPython.config import Application
log = Application.instance().log

Then log as normal, and it will go to the engine logs.



来源:https://stackoverflow.com/questions/15146168/ipython-parallel-can-i-write-my-own-log-into-the-engine-logs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!