New in version 0.5.2, only available for distributed scheduler.
For a distributed setting, the log output in custom functions, for instance,
submitted via mars.remote.spawn, will not reveal on client,
Users may have to login to the workers to see the log.
Hence, fetch_log API is used to retrieve the log to client for display purpose.
For example, we define a function called calculate.
>>> from mars.session import new_session
>>> # create a distributed session
>>> import mars.remote as mr
>>> def calculate(x):
>>> acc = 0
>>> for i in range(x):
>>> acc += i
>>> return acc
Then we trigger the execution, we can see that no output can be revealed just like expected.
>>> r = mr.spawn(calculate, 10)
Object <op=RemoteFunction, key=67b91ee22e4153107c615797bdb6c189>
You can use r.fetch_log() to retrieve the output.
>>> print(r.fetch_log()) # call fetch_log again will continue to fetch
>>> print(r.fetch_log(offsets=0)) # set offsets=0 to retrieve from beginning
Combining asynchronous execution with fetch_log,
it’s able to retrieve log continuously during running.
>>> import time
>>> def c_calc():
>>> for i in range(10):
>>> r = mr.spawn(c_calc)
>>> def run():
>>> f = r.execute(wait=False)
>>> while not f.done():
>>> log = str(r.fetch_log()).strip()
>>> if log: