Child processes created with python multiprocessing module won't print

前端 未结 4 1376
情歌与酒
情歌与酒 2020-11-27 08:12

I have a problem with the code below, and with any code that uses the print function in the child processes. I can\'t see any printed statements, even if I use

4条回答
  •  感情败类
    2020-11-27 08:34

    Try this:

    from multiprocessing import Process
    import sys
    
    def f(name):
        print 'hello', name
        sys.stdout.flush()
    
    ...
    

    AFAIK the standard output of processed spawned by the multiprocessing module is buffered, hence you will see the output only if the buffer becomes full or you explicitly flush sys.stdout.

提交回复
热议问题