ATLAS Offline Software
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
python.Helpers.ShutUp Class Reference
Inheritance diagram for python.Helpers.ShutUp:
Collaboration diagram for python.Helpers.ShutUp:

Public Member Functions

def __init__ (self, filters=DefaultFilter)
 
def __del__ (self)
 
def mute (self)
 
def unMute (self)
 
def __enter__ (self)
 
def __exit__ (self, exc_type, exc_val, exc_tb)
 

Public Attributes

 save_err
 
 save_out
 
 quiet_err
 
 quiet_out
 
 filters
 

Static Public Attributes

 DefaultFilter
 

Private Member Functions

def __filterRootMessages (self, fd)
 

Private Attributes

 _dummy
 

Detailed Description

A little helper class to keep ROOT silent...

Definition at line 63 of file Tools/PyUtils/python/Helpers.py.

Constructor & Destructor Documentation

◆ __init__()

def python.Helpers.ShutUp.__init__ (   self,
  filters = DefaultFilter 
)

Definition at line 72 of file Tools/PyUtils/python/Helpers.py.

72  def __init__(self, filters = DefaultFilter):
73  self._dummy = False # if dummy, we don't really shut-up ROOT...
74  if os.environ.get('PYUTILS_SHUTUP_DEBUG', '0') == '1':
75  self._dummy = True
76 
77  self.save_err = open( '/dev/null', 'w' )
78  self.save_out = open( '/dev/null', 'w' )
79  try:
80  self.quiet_err = NamedTemporaryFile( suffix = ".msg.log" )
81  self.quiet_out = NamedTemporaryFile( suffix = ".msg.log" )
82  except OSError:
83  # load problem ?
84  # retry a bit later... (in 2 seconds)
85  import time
86  time.sleep(2) #
87  try:
88  self.quiet_err = NamedTemporaryFile( suffix = ".msg.log" )
89  self.quiet_out = NamedTemporaryFile( suffix = ".msg.log" )
90  except OSError:
91  # then (implicitly) fallback on sys.stderr
92  self._dummy = True
93 
94  self.filters = filters
95 
96  if not self._dummy:
97  os.dup2( sys.stderr.fileno(), self.save_err.fileno() )
98  os.dup2( sys.stdout.fileno(), self.save_out.fileno() )
99  return
100 

◆ __del__()

def python.Helpers.ShutUp.__del__ (   self)

Definition at line 101 of file Tools/PyUtils/python/Helpers.py.

101  def __del__ (self):
102  self.save_err.close()
103  self.save_out.close()
104  return
105 

Member Function Documentation

◆ __enter__()

def python.Helpers.ShutUp.__enter__ (   self)

Definition at line 136 of file Tools/PyUtils/python/Helpers.py.

136  def __enter__(self):
137  return self.mute()

◆ __exit__()

def python.Helpers.ShutUp.__exit__ (   self,
  exc_type,
  exc_val,
  exc_tb 
)

Definition at line 138 of file Tools/PyUtils/python/Helpers.py.

138  def __exit__(self,exc_type, exc_val, exc_tb):
139  return self.unMute()
140 
141 
142 @cache

◆ __filterRootMessages()

def python.Helpers.ShutUp.__filterRootMessages (   self,
  fd 
)
private

Definition at line 122 of file Tools/PyUtils/python/Helpers.py.

122  def __filterRootMessages(self, fd):
123  fd.seek(0)
124  for l in fd.readlines():
125  l = l.decode()
126  printOut = True
127  for filter in self.filters:
128  if re.match(filter, l):
129  printOut = False
130  if printOut:
131  print ("PyRoot:",l.replace("\n",""))
132  pass
133  return
134 

◆ mute()

def python.Helpers.ShutUp.mute (   self)

Definition at line 106 of file Tools/PyUtils/python/Helpers.py.

106  def mute(self):
107  if not self._dummy:
108  os.dup2( self.quiet_err.fileno(), sys.stderr.fileno() )
109  os.dup2( self.quiet_out.fileno(), sys.stdout.fileno() )
110  return
111 

◆ unMute()

def python.Helpers.ShutUp.unMute (   self)

Definition at line 112 of file Tools/PyUtils/python/Helpers.py.

112  def unMute(self):
113  if not self._dummy:
114  os.dup2( self.save_err.fileno(), sys.stderr.fileno() )
115  os.dup2( self.save_out.fileno(), sys.stdout.fileno() )
116  self.__filterRootMessages(self.quiet_err)
117  self.quiet_err.seek(0)
118  self.__filterRootMessages(self.quiet_out)
119  self.quiet_out.seek(0)
120  return
121 

Member Data Documentation

◆ _dummy

python.Helpers.ShutUp._dummy
private

Definition at line 73 of file Tools/PyUtils/python/Helpers.py.

◆ DefaultFilter

python.Helpers.ShutUp.DefaultFilter
static

Definition at line 67 of file Tools/PyUtils/python/Helpers.py.

◆ filters

python.Helpers.ShutUp.filters

Definition at line 94 of file Tools/PyUtils/python/Helpers.py.

◆ quiet_err

python.Helpers.ShutUp.quiet_err

Definition at line 80 of file Tools/PyUtils/python/Helpers.py.

◆ quiet_out

python.Helpers.ShutUp.quiet_out

Definition at line 81 of file Tools/PyUtils/python/Helpers.py.

◆ save_err

python.Helpers.ShutUp.save_err

Definition at line 77 of file Tools/PyUtils/python/Helpers.py.

◆ save_out

python.Helpers.ShutUp.save_out

Definition at line 78 of file Tools/PyUtils/python/Helpers.py.


The documentation for this class was generated from the following file:
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
Trk::open
@ open
Definition: BinningType.h:40
python.AthDsoLogger.__del__
def __del__(self)
Definition: AthDsoLogger.py:82