I am trying to use Sage's parallelization with @parallel(p_iter='fork')
(I need fork
specifically to work around the problems brought up here.)
If I use print
to show some messages, they only appear when the parallelized function has finished. Example:
@parallel(1, timeout=10)
def fun(x):
print('Starting %d' % x)
sleep(5)
print('Finished %d' % x)
return x*x
list(fun([2,3,4]))
The "Starting" and the "Finished" messages show up simultaneously, even though they are issued with a 5 second time difference.
How can I print a message so that it will show up immediately?
I need this when I am running a Sage script in a terminal. I am not using Sage interactively in this case and I am not using the notebook interface.