ATLAS Offline Software
Loading...
Searching...
No Matches
athenaEF_tdaq_infra.Infrastructure Class Reference
Collaboration diagram for athenaEF_tdaq_infra.Infrastructure:

Public Member Functions

 __init__ (self, args)
 __del__ (self)
 register_handlers (self)
 start (self)
 start_webproxy (self)
 check_alive (self)
 copy_histograms (self)
 stop (self)

Public Attributes

 args = args
list processes = []
 pid = os.getpid()
bool ready = False
dict prehandlers = {}

Static Public Attributes

list sigs

Protected Member Functions

 _handle_quit (self, signum, frame)
 _implant_bomb (self)
 _launch (self, name, cmd)

Protected Attributes

 _handle_quit

Detailed Description

Manage the private TDAQ infrastructure (adapted from HLTMPPy.runner.Infrastructure)

Definition at line 88 of file athenaEF_tdaq_infra.py.

Constructor & Destructor Documentation

◆ __init__()

athenaEF_tdaq_infra.Infrastructure.__init__ ( self,
args )

Definition at line 94 of file athenaEF_tdaq_infra.py.

94 def __init__(self, args):
95 self.args = args
96 self.processes = [] # (name, subprocess.Popen)
97 self.pid = os.getpid() # Distinguish mother from children after forking
98 self.ready = False # True once all servers are up
99 self.register_handlers()
100

◆ __del__()

athenaEF_tdaq_infra.Infrastructure.__del__ ( self)
Stop infrastructure in the mother process, in case program exits before stop()

Definition at line 101 of file athenaEF_tdaq_infra.py.

101 def __del__(self):
102 """Stop infrastructure in the mother process, in case program exits before stop()"""
103 if os.getpid() == self.pid:
104 self.stop()
105

Member Function Documentation

◆ _handle_quit()

athenaEF_tdaq_infra.Infrastructure._handle_quit ( self,
signum,
frame )
protected

Definition at line 112 of file athenaEF_tdaq_infra.py.

112 def _handle_quit(self, signum, frame):
113 log.info('Caught signal %d. Cleaning up the infrastructure and exiting', signum)
114 self.stop()
115 prehandler = self.prehandlers.pop(signum, signal.SIG_DFL)
116 signal.signal(signum, prehandler)
117 sys.exit(0)
118

◆ _implant_bomb()

athenaEF_tdaq_infra.Infrastructure._implant_bomb ( self)
protected
preexec_fn ensuring infrastructure processes exit when this process dies

Definition at line 119 of file athenaEF_tdaq_infra.py.

119 def _implant_bomb(self):
120 """preexec_fn ensuring infrastructure processes exit when this process dies"""
121 from ctypes import cdll
122 PR_SET_PDEATHSIG = 1
123 try:
124 return lambda: cdll['libc.so.6'].prctl(PR_SET_PDEATHSIG, signal.SIGKILL)
125 except Exception:
126 log.error('Error setting PR_SET_PDEATHSIG for infrastructure processes. '
127 'Using a dummy function instead')
128 return lambda: 1
129

◆ _launch()

athenaEF_tdaq_infra.Infrastructure._launch ( self,
name,
cmd )
protected

Definition at line 130 of file athenaEF_tdaq_infra.py.

130 def _launch(self, name, cmd):
131 logbase = os.path.join(self.args.log_dir, f'{name}_{self.args.partition}')
132 proc = subprocess.Popen(cmd, preexec_fn=self._implant_bomb(),
133 stdout=open(logbase + '.out', 'w'),
134 stderr=open(logbase + '.err', 'w'),
135 close_fds=True)
136 log.info('Started %s (pid %d): %s', name, proc.pid, ' '.join(cmd))
137 self.processes.append((name, proc))
138 return proc
139

◆ check_alive()

athenaEF_tdaq_infra.Infrastructure.check_alive ( self)
Return False if any infrastructure process has exited

Definition at line 191 of file athenaEF_tdaq_infra.py.

191 def check_alive(self):
192 """Return False if any infrastructure process has exited"""
193 for name, proc in self.processes:
194 ret = proc.poll()
195 if ret is not None:
196 log.error('Infrastructure process %s (pid %d) exited with code %s',
197 name, proc.pid, ret)
198 return False
199 return True
200

◆ copy_histograms()

athenaEF_tdaq_infra.Infrastructure.copy_histograms ( self)

Definition at line 201 of file athenaEF_tdaq_infra.py.

201 def copy_histograms(self):
202 fname = f'r{self.args.run_number:010d}_{self.args.partition}_{self.args.oh_server}.root'
203 log.info('Copying histograms into %s (oh_cp)', fname)
204 subprocess.call(['oh_cp', '-p', self.args.partition, '-s', self.args.oh_server,
205 '-n', '.*', '-o', '.*', '-O',
206 '-r', str(self.args.run_number), '-f', fname])
207

◆ register_handlers()

athenaEF_tdaq_infra.Infrastructure.register_handlers ( self)

Definition at line 106 of file athenaEF_tdaq_infra.py.

106 def register_handlers(self):
107 self.prehandlers = {}
108 for s in self.sigs:
109 self.prehandlers[s] = signal.getsignal(s)
110 signal.signal(s, self._handle_quit)
111

◆ start()

athenaEF_tdaq_infra.Infrastructure.start ( self)

Definition at line 140 of file athenaEF_tdaq_infra.py.

140 def start(self):
141 from ispy import IPCPartition
142
143 partition = self.args.partition
144
145 # Private IPC domain: reference file local to this job's directory
146 ipc_ref = 'file:' + os.path.join(os.getcwd(), 'ipc_init.ref')
147 log.info('Setting TDAQ_IPC_INIT_REF: %s', ipc_ref)
148 os.environ['TDAQ_IPC_INIT_REF'] = ipc_ref
149
150 log.info('Initializing OH monitoring infrastructure for partition %s', partition)
151
152 self._launch('ipc_initial', ['ipc_server'])
153 while not IPCPartition('initial').isValid():
154 log.info('Waiting until initial partition is available...')
155 time.sleep(1)
156
157 self._launch('ipc_partition', ['ipc_server', '-p', partition])
158 while not IPCPartition(partition).isValid():
159 log.info('Waiting until partition %s is available...', partition)
160 time.sleep(1)
161
162 for server in ['DF', 'RunParams', self.args.oh_server]:
163 self._launch(f'is_{server}', ['is_server', '-p', partition, '-n', server])
164
165 self.start_webproxy()
166 self.ready = True
167

◆ start_webproxy()

athenaEF_tdaq_infra.Infrastructure.start_webproxy ( self)
Start the webproxy REST server

Definition at line 168 of file athenaEF_tdaq_infra.py.

168 def start_webproxy(self):
169 """Start the webproxy REST server"""
170 port = self.args.webdaq_port
171 webproxy = self._launch('webproxy', ['webproxy', '-p', str(port)])
172
173 timeout = 60
174 for _ in range(timeout):
175 if webproxy.poll() is not None:
176 log.error('webproxy exited early (code %s); see webproxy_%s.err',
177 webproxy.returncode, self.args.partition)
178 self.stop()
179 sys.exit(1)
180 try:
181 with socket.create_connection(('localhost', port), timeout=1):
182 log.info('webproxy listening on http://localhost:%d', port)
183 return
184 except OSError:
185 time.sleep(1)
186
187 log.error('webproxy is not listening on localhost:%d after %d s', port, timeout)
188 self.stop()
189 sys.exit(1)
190

◆ stop()

athenaEF_tdaq_infra.Infrastructure.stop ( self)

Definition at line 208 of file athenaEF_tdaq_infra.py.

208 def stop(self):
209 if not self.processes:
210 return
211
212 if self.ready: # Nothing was ever published if we did not fully start
213 self.copy_histograms()
214
215 log.info('Finalizing OH monitoring infrastructure')
216 for part in [self.args.partition, 'initial']:
217 log.info('Destroying partition: %s', part)
218 subprocess.call(['ipc_rm', '-f', '-p', part, '-i', '".*"', '-n', '".*"'],
219 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
220
221 for name, proc in self.processes:
222 while proc.poll() is None:
223 proc.kill()
224 time.sleep(0.1)
225 self.processes = []
226 log.info('Terminated all infrastructure processes')
227
228

Member Data Documentation

◆ _handle_quit

athenaEF_tdaq_infra.Infrastructure._handle_quit
protected

Definition at line 110 of file athenaEF_tdaq_infra.py.

◆ args

athenaEF_tdaq_infra.Infrastructure.args = args

Definition at line 95 of file athenaEF_tdaq_infra.py.

◆ pid

athenaEF_tdaq_infra.Infrastructure.pid = os.getpid()

Definition at line 97 of file athenaEF_tdaq_infra.py.

◆ prehandlers

dict athenaEF_tdaq_infra.Infrastructure.prehandlers = {}

Definition at line 107 of file athenaEF_tdaq_infra.py.

◆ processes

list athenaEF_tdaq_infra.Infrastructure.processes = []

Definition at line 96 of file athenaEF_tdaq_infra.py.

◆ ready

bool athenaEF_tdaq_infra.Infrastructure.ready = False

Definition at line 98 of file athenaEF_tdaq_infra.py.

◆ sigs

list athenaEF_tdaq_infra.Infrastructure.sigs
static
Initial value:
= [signal.SIGFPE, signal.SIGHUP, signal.SIGQUIT, signal.SIGSEGV,
signal.SIGTERM, signal.SIGINT]

Definition at line 91 of file athenaEF_tdaq_infra.py.


The documentation for this class was generated from the following file: