本文整理汇总了Python中sys.exit函数的典型用法代码示例。如果您正苦于以下问题:Python exit函数的具体用法?Python exit怎么用?Python exit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了exit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _clone_test_db
def _clone_test_db(self, suffix, verbosity, keepdb=False):
source_database_name = self.connection.settings_dict['NAME']
target_database_name = self.get_test_db_clone_settings(suffix)['NAME']
test_db_params = {
'dbname': self.connection.ops.quote_name(target_database_name),
'suffix': self.sql_table_creation_suffix(),
}
with self._nodb_connection.cursor() as cursor:
try:
self._execute_create_test_db(cursor, test_db_params, keepdb)
except Exception:
try:
if verbosity >= 1:
self.log('Destroying old test database for alias %s...' % (
self._get_database_display_str(verbosity, target_database_name),
))
cursor.execute('DROP DATABASE %(dbname)s' % test_db_params)
self._execute_create_test_db(cursor, test_db_params, keepdb)
except Exception as e:
self.log('Got an error recreating the test database: %s' % e)
sys.exit(2)
dump_cmd = DatabaseClient.settings_to_cmd_args(self.connection.settings_dict)
dump_cmd[0] = 'mysqldump'
dump_cmd[-1] = source_database_name
load_cmd = DatabaseClient.settings_to_cmd_args(self.connection.settings_dict)
load_cmd[-1] = target_database_name
dump_proc = subprocess.Popen(dump_cmd, stdout=subprocess.PIPE)
load_proc = subprocess.Popen(load_cmd, stdin=dump_proc.stdout, stdout=subprocess.PIPE)
dump_proc.stdout.close() # allow dump_proc to receive a SIGPIPE if load_proc exits.
load_proc.communicate()
示例2: make_cache_level
def make_cache_level(ncaches, prototypes, level, next_cache):
global next_subsys_index, proto_l1, testerspec, proto_tester
index = next_subsys_index[level]
next_subsys_index[level] += 1
# Create a subsystem to contain the crossbar and caches, and
# any testers
subsys = SubSystem()
setattr(system, "l%dsubsys%d" % (level, index), subsys)
# The levels are indexing backwards through the list
ntesters = testerspec[len(cachespec) - level]
# Scale the progress threshold as testers higher up in the tree
# (smaller level) get a smaller portion of the overall bandwidth,
# and also make the interval of packet injection longer for the
# testers closer to the memory (larger level) to prevent them
# hogging all the bandwidth
limit = (len(cachespec) - level + 1) * 100000000
testers = [proto_tester(interval=10 * (level * level + 1), progress_check=limit) for i in xrange(ntesters)]
if ntesters:
subsys.tester = testers
if level != 0:
# Create a crossbar and add it to the subsystem, note that
# we do this even with a single element on this level
xbar = L2XBar()
subsys.xbar = xbar
if next_cache:
xbar.master = next_cache.cpu_side
# Create and connect the caches, both the ones fanning out
# to create the tree, and the ones used to connect testers
# on this level
tree_caches = [prototypes[0]() for i in xrange(ncaches[0])]
tester_caches = [proto_l1() for i in xrange(ntesters)]
subsys.cache = tester_caches + tree_caches
for cache in tree_caches:
cache.mem_side = xbar.slave
make_cache_level(ncaches[1:], prototypes[1:], level - 1, cache)
for tester, cache in zip(testers, tester_caches):
tester.port = cache.cpu_side
cache.mem_side = xbar.slave
else:
if not next_cache:
print "Error: No next-level cache at top level"
sys.exit(1)
if ntesters > 1:
# Create a crossbar and add it to the subsystem
xbar = L2XBar()
subsys.xbar = xbar
xbar.master = next_cache.cpu_side
for tester in testers:
tester.port = xbar.slave
else:
# Single tester
testers[0].port = next_cache.cpu_side
示例3: bug_found
def bug_found(self):
"""
Builds a crash-report when StarCluster encounters an unhandled
exception. Report includes system info, python version, dependency
versions, and a full debug log and stack-trace of the crash.
"""
dashes = '-' * 10
header = dashes + ' %s ' + dashes + '\n'
crashfile = open(static.CRASH_FILE, 'w')
argv = sys.argv[:]
argv[0] = os.path.basename(argv[0])
argv = ' '.join(argv)
crashfile.write(header % "SYSTEM INFO")
crashfile.write("StarCluster: %s\n" % __version__)
crashfile.write("Python: %s\n" % sys.version.replace('\n', ' '))
crashfile.write("Platform: %s\n" % platform.platform())
dependencies = ['boto', 'paramiko', 'Crypto']
for dep in dependencies:
self.__write_module_version(dep, crashfile)
crashfile.write("\n" + header % "CRASH DETAILS")
crashfile.write('Command: %s\n\n' % argv)
for line in logger.get_session_log():
crashfile.write(line)
crashfile.close()
print
log.error("Oops! Looks like you've found a bug in StarCluster")
log.error("Crash report written to: %s" % static.CRASH_FILE)
log.error("Please remove any sensitive data from the crash report")
log.error("and submit it to [email protected]")
sys.exit(1)
示例4: main
def main(name):
try:
from python_qt_binding.QtGui import QApplication
except:
print >> sys.stderr, "please install 'python_qt_binding' package!!"
sys.exit(-1)
masteruri = init_cfg_path()
parser = init_arg_parser()
args = rospy.myargv(argv=sys.argv)
parsed_args = parser.parse_args(args[1:])
# Initialize Qt
global app
app = QApplication(sys.argv)
# decide to show main or echo dialog
global main_form
if parsed_args.echo:
main_form = init_echo_dialog(name, masteruri, parsed_args.echo[0], parsed_args.echo[1], parsed_args.hz)
else:
main_form = init_main_window(name, masteruri, parsed_args.file)
# resize and show the qt window
if not rospy.is_shutdown():
os.chdir(PACKAGE_DIR) # change path to be able to the images of descriptions
main_form.resize(1024, 720)
screen_size = QApplication.desktop().availableGeometry()
if main_form.size().width() >= screen_size.width() or main_form.size().height() >= screen_size.height()-24:
main_form.showMaximized()
else:
main_form.show()
exit_code = -1
rospy.on_shutdown(finish)
exit_code = app.exec_()
示例5: run
def run(arguments=sys.argv[1:]):
# parse the command line arguments
(options, command) = parse_args(arguments)
# ensure the binary is given
if not options.binary:
print "Please provide a path to your Firefox binary: -b, --binary"
sys.exit(1)
# set the BROWSER_PATH environment variable so that
# subshells will be able to invoke mozrunner
os.environ['BROWSER_PATH'] = options.binary
# Parse the manifest
mp = TestManifest(manifests=(options.manifest,), strict=False)
# run + report
if command == "testpy":
tests = mp.active_tests(disabled=False)
results = test_all_python(mp.get(tests=tests, type='python'), options)
if results.failures or results.errors:
sys.exit(report(True, results, None, options))
else:
sys.exit(report(False))
elif command == "testjs":
tests = mp.active_tests(disabled=False)
results = test_all_js(mp.get(tests=tests, type='javascript'), options)
if results.fails:
sys.exit(report(True, None, results, options))
else:
sys.exit(report(False))
elif command == "testall":
test_all(mp.active_tests(disabled=False), options)
示例6: chainref_cmd
def chainref_cmd ( cmd, host='/tmp/chainrefd', log=None ):
if ( len(cmd) > 1 ):
arg = cmd[1]
else:
arg = None
if ( cmd[0] not in COMMANDS ):
print 'chainref-cmd: invalid command \'%s\'' % cmd[0]
return
if ( cmd[0].startswith('ajax') ):
host = '/tmp/chainref-ajax-0'
if ( arg != None ):
content = COMMANDS[cmd[0]] ( arg )
else:
content = COMMANDS[cmd[0]] ( )
s = socket.socket ( socket.AF_UNIX, socket.SOCK_STREAM )
try:
s.connect ( host )
s.send ( content )
except Exception,e:
print 'chainref-cmd: communication with server failed: %s' % str(e)
s.close ( )
sys.exit ( 1 )
示例7: clean_up
def clean_up(self):
""" Move DQ outputs to their appropriate directory """
try:
data_dir = os.environ["DATA"]
plots_dir = os.environ["PLOTS"]
logs_dir = os.environ["LOGS"]
except KeyError as detail:
print "GenerateSpectrum.clean_up: error", detail, "not set"
print " --> source analysis environment scripts before running!"
sys.exit(1)
for root, dirs, files in os.walk(os.getcwd()):
for file in files:
is_data = re.search(r".*\.root$", file)
is_plot = re.search(r".*\.png$", file)
hostname = socket.gethostname()
is_log = re.search(r"^rat\."+hostname+r"\.[0-9]+\.log$", file)
if is_data:
try:
root_file = TFile(file)
tree = root_file.Get("T")
tree.ls()
except ReferenceError as detail:
"generate_spectrum.clean_up: error in TFile,", detail
sys.exit(1)
file_manips.copy_file(os.path.join(root, file), data_dir)
elif is_plot:
file_manips.copy_file(os.path.join(root, file), plots_dir)
elif is_log:
file_manips.copy_file(os.path.join(root, file), logs_dir)
示例8: main
def main():
if sys.argv[1:]:
try:
fp = open(sys.argv[1], 'r')
except IOError, msg:
print 'Can\'t open "%s":' % sys.argv[1], msg
sys.exit(1)
示例9: _maybe_extract
def _maybe_extract(fpath, dirname, descend=True):
path = os.path.dirname(fpath)
untar_fpath = os.path.join(path, dirname)
if not os.path.exists(untar_fpath):
print('Extracting contents of "{}"...'.format(dirname))
tfile = zipfile.ZipFile(fpath, 'r')
try:
tfile.extractall(untar_fpath)
except (Exception, KeyboardInterrupt) as e:
if os.path.exists(untar_fpath):
if os.path.isfile(untar_fpath):
os.remove(untar_fpath)
else:
shutil.rmtree(untar_fpath)
raise
tfile.close()
if descend:
dirs = [os.path.join(untar_fpath, o)
for o in os.listdir(untar_fpath)
if os.path.isdir(os.path.join(untar_fpath, o))]
if len(dirs) != 1:
print("Error, found not exactly one dir: {}".format(dirs))
sys.exit(-1)
return dirs[0]
else:
return untar_fpath
示例10: setInitialCondition
def setInitialCondition(self,U0):
if np.shape(self.U) != np.shape(U0):
print "Wrong shape",np.shape(U0)," of initial condition! Must match shape of mesh",np.shape(self.mesh),". Exiting"
# U0 = U0[:np.shape(self.U)[0],:np.shape(self.U)[-1]]
import sys
sys.exit(0)
self.Up = U0
示例11: option_none
def option_none(option, opt, value, parser):
""" checks a parameter for taking value"""
if parser.rargs and not parser.rargs[0].startswith('-'):
print "Option arg error"
print opt, " option should be empty"
sys.exit(2)
setattr(parser.values, option.dest, True)
示例12: main
def main():
idir, ofile, dffile = _parse_cmdline()
print u'Loading doc-freqs file {}...'.format(dffile)
with open(dffile, 'rb') as f:
df = pickle.load(f)
print u'Reading input directory: {}'.format(idir)
jobs = _load_jobs(idir, df)
# Do the work.
pool = Pool(4)
njobs = len(jobs)
try:
import sys
with codecs.open(ofile, 'wb') as pf:
pickle.dump(njobs, pf)
results = pool.imap_unordered(worker, jobs)
for i, result in enumerate(results, 1):
pickle.dump(result, pf)
per = 100 * (float(i) / njobs)
sys.stdout.write(u'\rPercent Complete: {:2.3f}%'.format(per))
sys.stdout.flush()
sys.stdout.write(u'\rPercent Complete: 100% \n')
sys.stdout.flush()
except KeyboardInterrupt:
sys.stdout.write(u'\rPercent Complete: {:2.3f}% \n'.format(per))
sys.stdout.write(u'Shutting down.\n')
sys.stdout.flush()
sys.exit()
print u'Complete!'
示例13: parse_subcommands
def parse_subcommands(self, gparser=None):
"""
Parse global arguments, find subcommand from list of subcommand
objects, parse local subcommand arguments and return a tuple of
global options, selected command object, command options, and
command arguments.
Call execute() on the command object to run. The command object has
members 'gopts' and 'opts' set for global and command options
respectively, you don't need to call execute with those but you could
if you wanted to.
"""
gparser = gparser or self.gparser
# parse global options.
gopts, args = gparser.parse_args()
if not args:
gparser.print_help()
raise SystemExit("\nError: you must specify an action.")
# set debug level if specified
if gopts.DEBUG:
console.setLevel(logger.DEBUG)
config.DEBUG_CONFIG = True
# load StarClusterConfig into global options
try:
cfg = config.StarClusterConfig(gopts.CONFIG)
cfg.load()
except exception.ConfigNotFound, e:
log.error(e.msg)
e.display_options()
sys.exit(1)
示例14: handle_completion
def handle_completion(self):
if self.is_completion_active():
gparser = self.create_global_parser(no_usage=True, add_help=False)
# set sys.path to COMP_LINE if it exists
self._init_completion()
# fetch the global options
gopts = self.get_global_opts()
# try to load StarClusterConfig into global options
if gopts:
try:
cfg = config.StarClusterConfig(gopts.CONFIG)
cfg.load()
except exception.ConfigError:
cfg = None
gopts.CONFIG = cfg
scmap = {}
for sc in commands.all_cmds:
sc.gopts = gopts
for n in sc.names:
scmap[n] = sc
listcter = completion.ListCompleter(scmap.keys())
subcter = completion.NoneCompleter()
completion.autocomplete(gparser, listcter, None, subcter,
subcommands=scmap)
sys.exit(1)
示例15: lookup_command
def lookup_command(command_name):
"""Lookup a command.
command_name: the command name
Returns: a method which implements that command
"""
BASE_COMMANDS = {'help': print_help}
REPLICATION_COMMANDS = {'compare': replication_compare,
'dump': replication_dump,
'livecopy': replication_livecopy,
'load': replication_load,
'size': replication_size}
commands = {}
for command_set in (BASE_COMMANDS, REPLICATION_COMMANDS):
commands.update(command_set)
try:
command = commands[command_name]
except KeyError:
if command_name:
sys.exit(_("Unknown command: %s") % command_name)
else:
command = commands['help']
return command