18
18
import os
19
19
20
20
21
- def bootstrap_sp (argvals ):
21
+ def bootstrap_sp (args ):
22
22
"""
23
- Bootstrap the multithreaded (single processing) version of the
24
- calculation.
23
+ Bootstrap the multithreaded (single processing) version of the calculation.
25
24
26
- :param argvals: Command line arguments parsed by argparse.
25
+ :param args: Dictionary of command line arguments parsed by argparse.
27
26
:return: (component-list, capability-table)
28
27
"""
29
28
@@ -32,17 +31,17 @@ def bootstrap_sp(argvals):
32
31
from cassandra .compfactory import create_component
33
32
34
33
# Configure logger
35
- if argvals . logdir is None :
36
- logging .basicConfig (stream = sys .stdout , level = argvals . loglvl )
34
+ if args [ ' logdir' ] is None :
35
+ logging .basicConfig (stream = sys .stdout , level = args [ ' loglvl' ] )
37
36
logging .info (f'This is Cassandra version { __version__ } .' )
38
37
else :
39
- os .makedirs (argvals . logdir , exist_ok = True )
40
- logging .basicConfig (filename = f' { argvals . logdir } /cassandra.log' ,
41
- level = argvals . loglvl , filemode = 'w' )
38
+ os .makedirs (args [ ' logdir' ] , exist_ok = True )
39
+ logging .basicConfig (filename = f" { args [ ' logdir' ] } /cassandra.log" ,
40
+ level = args [ ' loglvl' ] , filemode = 'w' )
42
41
# Write to screen the location of the logging output
43
- print (f' This is Cassandra version { __version__ } . Output will be logged to { argvals . logdir } /cassandra.log' )
42
+ print (f" This is Cassandra version { __version__ } . Output will be logged to { args [ ' logdir' ] } /cassandra.log" )
44
43
45
- cfgfile_name = argvals . ctlfile
44
+ cfgfile_name = args [ ' ctlfile' ]
46
45
47
46
# initialize the structures that will receive the data we are
48
47
# parsing from the file
@@ -68,24 +67,51 @@ def bootstrap_sp(argvals):
68
67
# end of bootstrap_sp
69
68
70
69
71
- def main (argvals ):
70
+ def main (args ):
71
+ """
72
+ Cassandra main entry function.
73
+
74
+ :param args: Dictionary of command line arguments parsed by argparse.
75
+
76
+ This function starts up the Cassandra framework, selecting either the
77
+ single-processing or multi-processing mode, as required. It's set up to be
78
+ run from the script block at the end of the module, but it could be called
79
+ from another program if desired. To do that you will need to set up a
80
+ dictionary simulating the command-line parameters from the stand-alone
81
+ version. The parameters that need to be supplied are:
82
+ ctlfile : Name of the configuration ("control") file.
83
+ mp : Flag indicating whether we are running in MP mode
84
+ logdir : Directory for log files. In SP mode this can be None, in
85
+ which case log outputs go to stdout
86
+ verbose : Flag indicating whether to produce debugging output.
87
+ quiet : Flag indicating whether to suppress output except for warnings
88
+ and error messages
89
+
90
+ Keep in mind that this function will throw an exception if any of the
91
+ components fail (whether by exception or by returning a failure code). It's
92
+ up to whatever code is calling it to handle any cleanup associated with the
93
+ failure. This is especially important if you are running in MP mode, as
94
+ failing to do this cleanup can hang the entire calculation.
95
+
96
+ """
97
+
72
98
73
99
# Set the appropriate logging level
74
100
# NB: You MUST NOT call any logging functions until either bootstrap_mp
75
101
# or bootstrap_sp has been called.
76
- if argvals . verbose :
77
- argvals . loglvl = logging .DEBUG
78
- elif argvals . quiet :
79
- argvals . loglvl = logging .WARNING
102
+ if args [ ' verbose' ] :
103
+ args [ ' loglvl' ] = logging .DEBUG
104
+ elif args [ ' quiet' ] :
105
+ args [ ' loglvl' ] = logging .WARNING
80
106
else :
81
- argvals . loglvl = logging .INFO
107
+ args [ ' loglvl' ] = logging .INFO
82
108
83
- if argvals . mp :
109
+ if args [ 'mp' ] :
84
110
# See notes in mp.py about side effects of importing that module.
85
111
from cassandra .mp import bootstrap_mp , finalize
86
- (component_list , cap_table ) = bootstrap_mp (argvals )
112
+ (component_list , cap_table ) = bootstrap_mp (args )
87
113
else :
88
- (component_list , cap_table ) = bootstrap_sp (argvals )
114
+ (component_list , cap_table ) = bootstrap_sp (args )
89
115
90
116
# We will look up "general" in the cap_table and process any
91
117
# global parameters here, but in the current version we don't
@@ -99,7 +125,7 @@ def main(argvals):
99
125
100
126
# Wait for all component threads to complete before printing end
101
127
# message.
102
- if argvals . mp :
128
+ if args [ 'mp' ] :
103
129
# The RAB thread will always be first in the thread list
104
130
component_threads = threads [1 :]
105
131
else :
@@ -114,7 +140,7 @@ def main(argvals):
114
140
# if the RAB is present, it is always the first in the list.
115
141
nfail = 0
116
142
117
- if argvals . mp :
143
+ if args [ 'mp' ] :
118
144
reg_comps = component_list [1 :]
119
145
rab_comp = component_list [0 ]
120
146
else :
@@ -140,7 +166,7 @@ def main(argvals):
140
166
141
167
# If this is a multiprocessing calculation, then we need to
142
168
# perform the finalization procedure
143
- if argvals . mp :
169
+ if args [ 'mp' ] :
144
170
finalize (component_list [0 ], threads [0 ])
145
171
146
172
logging .info ("\n FIN." )
@@ -163,7 +189,7 @@ def main(argvals):
163
189
164
190
try :
165
191
# status is the number of component failures.
166
- status = main (argvals )
192
+ status = main (vars ( argvals ) )
167
193
except Exception as err :
168
194
if argvals .mp :
169
195
from mpi4py import MPI
0 commit comments