Belle II Software  release-08-01-10
_override_print.py
1 #!/usr/bin/env python3
2 
3 
10 
11 """
12 This is a small module to replace the builtin print function with one that
13 flushes by default.
14 
15 This is necessary as we mix a lot of C++ and python output and this means we
16 need to flush the output frequently otherwise the order of lines is totally
17 garbled
18 
19 It overrides the function in the builtins module so this will propagate to
20 everywhere. We do this in a extra module to be able to check the python version
21 on `import basf2`.
22 """
23 
24 import builtins
25 
26 
27 def flush_print(*args, **argk):
28  """print function which flushes by default"""
29  argk.setdefault("flush", True)
30  builtins._print(*args, **argk)
31 
32 
33 # remember original print function
34 builtins._print = print
35 # and replace it with the flushing one
36 builtins.print = flush_print