Belle II Software  release-08-01-10
stop_on_error.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import os
12 import basf2
13 
14 basf2.set_random_seed("")
15 
16 
17 class ErrorInInit(basf2.Module):
18  """test"""
19 
20  def initialize(self):
21  """reimplementation of Module::initialize()."""
22  basf2.B2ERROR("In module " + self.name())
23 
24 
25 class ErrorInEvent(basf2.Module):
26  """test"""
27 
28  def event(self):
29  """reimplementation of Module::event()."""
30  # error level to check that this doesn't prevent execution
31  basf2.B2ERROR("In module " + self.name())
32 
33 
34 noerrors = basf2.Path()
35 noerrors.add_module('EventInfoSetter')
36 
37 # no errors at all
38 basf2.process(noerrors)
39 
40 errorsinevent = basf2.Path()
41 errorsinevent.add_module('EventInfoSetter')
42 errorsinevent.add_module(ErrorInEvent())
43 
44 # no errors before event processing
45 basf2.process(errorsinevent)
46 
47 # there were errors in event() of previous run
48 basf2.process(noerrors)
49 basf2.process(noerrors)
50 basf2.process(errorsinevent)
51 # there were some more errors in event() of previous run
52 basf2.process(noerrors)
53 
54 # errors in initialize() -> fail
55 if os.fork() == 0:
56  noerrors.add_module(ErrorInInit())
57  basf2.process(noerrors)
58 else:
59  assert os.wait()[1] != 0
60 
61 # errors before process() -> fail
62 if os.fork() == 0:
63  basf2.B2ERROR("htns")
64  basf2.process(noerrors)
65 else:
66  assert os.wait()[1] != 0
67 
68 basf2.B2INFO('everything was OK.')