Ordering issue of message and print

Issue #100 invalid
Yingchao Lu created an issue

The order of message and print not normal using mpi4py in python3.

test2.py

import warnings
import time

warnings.warn("a")
time.sleep(5)
print("b")

The print result b should go after the warning. It is normal without mpi

>> python3 test2.py             
test2.py:4: UserWarning: a
  warnings.warn("a")
b

But with mpi the order is not normal

>> mpirun -np 1 python3 test2.py
b
test2.py:4: UserWarning: a
  warnings.warn("a")

The problem only appears in python3, not in python2.

>> mpirun -np 1 python2 test2.py
test2.py:4: UserWarning: a
  warnings.warn("a")
b

Comments (8)

  1. Lisandro Dalcin

    Can you please take a second look at the final snippet you posted? You are not using mpi4py at all!! Who can this be an mpi4py issue? Long story short, this is related to the way Python 3 implements buffered IO, and its interaction with mpiexec and the way it forwards and merge output from the many processes in a run . If you use unbuffered IO (python -u flag), you should get the expected out:

    $ mpiexec -n 1 python3 -u test2.py 
    snippet.py:4: UserWarning: a
      warnings.warn("a")
    b
    

    Thus, this IS NOT an mpi4py issue.

  2. Log in to comment