• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python sys.exit函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sys.exit函数的典型用法代码示例。如果您正苦于以下问题:Python exit函数的具体用法?Python exit怎么用?Python exit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了exit函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
开发者ID:NewbiePanda,项目名称:django,代码行数:32,代码来源:creation.py


示例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
开发者ID:rallylee,项目名称:gem5,代码行数:60,代码来源:memtest.py


示例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)
开发者ID:AlexMikhalev,项目名称:StarCluster,代码行数:30,代码来源:cli.py


示例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_()
开发者ID:awesomebytes,项目名称:multimaster_fkie,代码行数:34,代码来源:__init__.py


示例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)
开发者ID:Ghost-script,项目名称:mozmill,代码行数:35,代码来源:mutt.py


示例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 )
开发者ID:coinorama,项目名称:coinorama,代码行数:27,代码来源:chainref-cmd.py


示例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)
开发者ID:ashleyrback,项目名称:MajoRat,代码行数:29,代码来源:generate_spectrum.py


示例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)
开发者ID:0xcc,项目名称:python-read,代码行数:7,代码来源:update.py


示例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
开发者ID:MartinThoma,项目名称:algorithms,代码行数:26,代码来源:gtsrb.py


示例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
开发者ID:fepettersen,项目名称:thesis,代码行数:7,代码来源:combine.py


示例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)
开发者ID:keedio,项目名称:nagios-plugin-couchbase,代码行数:7,代码来源:check_couchbase.py


示例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!'
开发者ID:kedz,项目名称:disasters,代码行数:34,代码来源:create_instance_vectors.py


示例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)
开发者ID:AlexMikhalev,项目名称:StarCluster,代码行数:30,代码来源:cli.py


示例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)
开发者ID:AlexMikhalev,项目名称:StarCluster,代码行数:25,代码来源:cli.py


示例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
开发者ID:froyobin,项目名称:xmonitor,代码行数:27,代码来源:replicator.py


示例16: auth_dialog

 def auth_dialog(self):
     try:
         with open(CONF_FILE) as conf:
             token = json.load(conf)
     except (OSError, json.JSONDecodeError, KeyError):
         print("Your token file doesn't exist or is malformed.")
         print("If you WANT to proceed anonymously, pass"
               "`-a/--anonymous` on the command line.")
         print("Or you can create a new token now. "
               "Create token? [y/n] ", end='')
         if input().lower() in ('y', 'yes'):
             username = input('Username: ')
             password = getpass.getpass()
             note = 'gist3_{}'.format(id_gen())
             resp = req.post(API_BASE + '/authorizations',
                             auth=(username, password),
                             json={'scopes': ['gist'],
                                   'note': note})
             if resp.status_code == req.codes.created:
                 token = resp.json()['token']
                 with open(CONF_FILE, 'w') as conf:
                     json.dump(token, conf)
                 print('Token created & saved to {}'.format(CONF_FILE))
             else:
                 print('There was an error from github: ')
                 print(json.dumps(resp.json(), sort_keys=True, indent=4))
                 sys.exit(2)
         else:
             print('Aborting...')
             sys.exit(0)
     return AccessTokenAuth(token)
开发者ID:jmsdvl,项目名称:gist3.py,代码行数:31,代码来源:cli.py


示例17: links

def links(args):
    """
    %prog links url

    Extract all the links "<a href=''>" from web page.
    """
    p = OptionParser(links.__doc__)
    p.add_option("--img", default=False, action="store_true",
                 help="Extract <img> tags [default: %default]")
    opts, args = p.parse_args(args)

    if len(args) != 1:
        sys.exit(not p.print_help())

    url, = args
    img = opts.img

    htmlfile = download(url)
    page = open(htmlfile).read()
    soup = BeautifulSoup(page)

    tag = 'img' if img else 'a'
    src = 'src' if img else 'href'
    aa = soup.findAll(tag)
    for a in aa:
        link = a.get(src)
        link = urljoin(url, link)
        print(link)
开发者ID:tanghaibao,项目名称:jcvi,代码行数:28,代码来源:html.py


示例18: main

def main():
    print '----------------------------------'
    print '-    Coursera.org Downloader     -'
    print '-         by Logan Ding          -'
    print '----------------------------------'
    print
    # Add courses by yourself. Not all tested. You can feed back.
    course = { '1' : 'modelthinking',
               '2' : 'gametheory',  
               '3' : 'crypto',
               '4' : 'saas',
               '5' : 'pgm', 
               '6' : 'algo'}

    # Your Coursera.org email and password needed here to download videos. 
    email = 'youremail'
    password = 'password'

    if email == 'youremail':
        print 'You must change the email and the password to yours in main() first.'
        sys.exit(1)

    path  = download_path()
    print 'All files will be downloaded to:', path
    print
    course = choose_course(course)
    br = initialize_browser(course, email, password)
    mp4, pdf, pptx = resolve_resources(br, path)
    downloader(mp4, pdf, pptx, br, path)
开发者ID:lorenzosantos,项目名称:Coursera.org-Downloader,代码行数:29,代码来源:coursera_downloader.py


示例19: _collect

    def _collect(self, lines):
        elements = {}
        tag = None
        for line_tmp in lines:
            line = line_tmp.replace('!', '#').split('#')[0]
            for val in [x.lower() for x in line.split()]:
                if val in self._set_methods:
                    tag = val
                    elements[tag] = []
                elif tag is not None:
                    elements[tag].append(val)

        for tag in ['natom', 'ntypat']:
            if tag not in elements:
                print("%s is not found in the input file." % tag)
                sys.exit(1)

        for tag in elements:
            self._values = elements[tag]
            if tag == 'natom' or tag == 'ntypat':
                self._set_methods[tag]()

        for tag in elements:
            self._values = elements[tag]
            if tag != 'natom' and tag != 'ntypat':
                self._set_methods[tag]()
开发者ID:atztogo,项目名称:phonopy,代码行数:26,代码来源:abinit.py


示例20: initialize_browser

def initialize_browser(course, email, password):
    #Use mechanize to handle cookie
    print
    print 'Initialize browsering session...'
    br = mechanize.Browser()
    cj = cookielib.LWPCookieJar()
    br.set_cookiejar(cj)
    br.set_handle_equiv(True)
    #br.set_handle_gzip(True)
    br.set_handle_redirect(True)
    br.set_handle_referer(True)
    br.set_handle_robots(False)
    br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time = 0)
    auth_url = 'https://www.coursera.org/****/auth/auth_redirector?type=login&subtype=normal&email'.replace('****', course)
    br.open(auth_url)

    br.select_form(nr = 0)
    br.form['email'] =  email
    br.form['password'] = password
    br.submit()
    print 'It takes seconds to login and resolve resources to download...\n'

    #Check if email + password submitted correctly
    if 'https://www.coursera.org/****/auth/login_receiver?data='.replace('****', course) not in br.geturl():
        print 'Failed to login, exit...'
        sys.exit(1)

    video_lectures = 'https://www.coursera.org/****/lecture/index'.replace('****', course)
    br.open(video_lectures)
    return br
开发者ID:lorenzosantos,项目名称:Coursera.org-Downloader,代码行数:30,代码来源:coursera_downloader.py



注:本文中的sys.exit函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sys.ext函数代码示例发布时间:2022-05-27
下一篇:
Python sys.exec_info函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap