ATLAS Offline Software
Loading...
Searching...
No Matches
Execution.py
Go to the documentation of this file.
2for script in opts.scripts:
3 try:
4 include( script )
5 except Exception as e:
6 if isinstance(e,SystemExit):
7 raise
8
9 # "sanitize" the traceback under the assumption that it is the user's fault
10 import traceback
11
12 if not _msg.isEnabledFor( logging.DEBUG ):
13 # "sanitize" the traceback under the assumption that it is the user's fault
14 exc_info = sys.exc_info()
15 tb = traceback.extract_tb( exc_info[2] )
16
17 short_tb = []
18 for frame_info in tb:
19 if not 'AthenaCommon' in frame_info[0]:
20 short_tb.append( frame_info )
21
22 print ('Shortened traceback (most recent user call last):')
23 print (''.join( traceback.format_list( short_tb ) ),)
24 print (''.join( traceback.format_exception_only( exc_info[0], exc_info[1] ) ),)
25 else:
26 traceback.print_exc()
27
28 if not opts.interactive:
29
30 # --- Start of CA-in-Legacy warning check ---
31 if opts.scripts:
32 try:
33 with open(opts.scripts[0], 'r') as f:
34 script_content = f.read(5000) #limit on large files
35 if "ComponentAccumulator" in script_content or "ConfigFlags" in script_content:
36 log.warning("The script '%s' appears to use ComponentAccumulator syntax,", opts.scripts[0])
37 log.warning("but athena.py is executing it in Legacy mode.")
38 log.warning("FIX: Add '#!/usr/bin/env athena.py' as the first line of your script.")
39 except Exception:
40 # We wrap this in a try/except to ensure a file-read error
41 # doesn't prevent the actual job from attempting to run.
42 pass
43 # --- End of warning check ---
44
45 # additional processing to get right error codes
46 import AthenaCommon.ExitCodes as ExitCodes
47 if isinstance( e, IncludeError ):
48 theApp._exitstate = ExitCodes.INCLUDE_ERROR
49 print('If the script is a ComponentAccumulator configuration, add a shebang (#!) '
50 'to its first line or run with the --CA option.\n')
51 elif isinstance( e, ImportError ):
52 theApp._exitstate = ExitCodes.IMPORT_ERROR
53 else:
54 theApp._exitstate = ExitCodes.UNKNOWN_EXCEPTION
55
56 del ExitCodes
57 theApp.exit()
58
59 # for interactive: drop into prompt
60 break
61
62else:
63
64 if "-h" in opts.user_opts or "--help" in opts.user_opts:
65 # The user script was displaying help messages stop here
66 # In most cases, the user script should kill the process already (argparse
67 # does this for you) but just in case print our help message and stop
68 from AthenaCommon.AthOptionsParser import _error_msg
69 print(_error_msg)
70 theApp.exit()
71
72
73 if opts.fromdb:
74 _msg.info( 'now loading %s ... ', opts.fromdb )
75 import AthenaCommon.ConfigurationShelve
76 AthenaCommon.ConfigurationShelve.loadJobOptionsCatalogue( opts.fromdb )
77 del AthenaCommon.ConfigurationShelve
78 if opts.fromdb.startswith( 'TempAthenaConfig.' ):
79 try:
80 os.remove( opts.fromdb )
81 except OSError:
82 pass
83 opts.fromdb = None
84
85
86 if opts.perfmon:
87 import PerfMonComps.PerfMonFlags as _pmf
88 _pmf._decode_pmon_opts(opts.perfmon.split(','))
89
90
91 if DbgStage.value == "init":
92 hookDebugger()
93
94
95 if not opts.fromdb and opts.nprocs and (opts.nprocs >= 1 or opts.nprocs==-1):
96 from AthenaCommon.AppMgr import ServiceMgr as svcMgr
97 import AthenaMP.PyComps as _amppy
98 svcMgr += _amppy.MpEvtLoopMgr(NWorkers=opts.nprocs)
99
100 #if EvtMax and SkipEvents are set, use them
101 from AthenaCommon.AthenaCommonFlags import jobproperties as jps
102 if jps.AthenaCommonFlags.EvtMax.statusOn:
103 theApp.EvtMax = jps.AthenaCommonFlags.EvtMax()
104 if jps.AthenaCommonFlags.SkipEvents.statusOn:
105 if hasattr(svcMgr,"EventSelector"):
106 if not hasattr(svcMgr, "SecondaryEventSelector"):
107 svcMgr.EventSelector.SkipEvents = jps.AthenaCommonFlags.SkipEvents()
108 else:
109 _msg.warning('No EventSelector in svcMgr, not skipping events')
110
111
112
113 if not opts.interactive:
114
115 include( "AthenaCommon/runbatch.py" )
116 else:
117 #pass
118 # done, back to the user
119
120
121 if opts.nprocs and (opts.nprocs >= 1 or opts.nprocs==-1):
122 _msg.warning('interactive mode not validated with AthenaMP')
123
124 _msg.info( 'entered interactive mode - have fun!' )
125 _msg.info( 'you can call theApp.run() to execute and use ctrl-d to exit' )
126 os.environ['PYTHONINSPECT'] = '1'
void print(char *figname, TCanvas *c1)