python - Supress output in multiprocessing process -


i have code runs in parallel using mulitprocessing pool class. unforntunately of functions use library have verbose output. abstract problem have @ following example:

from multiprocessing import pool  def f(x):     print 'hello'     return x*x  p = pool(10) p.map(f, [1,2,3]) 

so print 'hello' 10 times. there possibility mute output of processes or put std.out in variable? suggestion.

edit: don't want redirect whole stdout, processes of pool.

use the initializer parameter call mute in worker processes:

import sys import os multiprocessing import pool  def mute():     sys.stdout = open(os.devnull, 'w')      def f(x):     print 'hello'     return x*x  if __name__ == '__main__':     p = pool(10, initializer=mute)     p.map(f, [1,2,3])     print('hello') 

prints

hello 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -