当前位置: 首页>>代码示例>>Python>>正文


Python os.exit方法代码示例

本文整理汇总了Python中os.exit方法的典型用法代码示例。如果您正苦于以下问题:Python os.exit方法的具体用法?Python os.exit怎么用?Python os.exit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在os的用法示例。


在下文中一共展示了os.exit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: start

# 需要导入模块: import os [as 别名]
# 或者: from os import exit [as 别名]
def start(self):
        """Start all services."""
        atexit.register(self._clean_exit)

        self.state = states.STARTING
        self.log('Bus STARTING')
        try:
            self.publish('start')
            self.state = states.STARTED
            self.log('Bus STARTED')
        except (KeyboardInterrupt, SystemExit):
            raise
        except Exception:
            self.log('Shutting down due to error in start listener:',
                     level=40, traceback=True)
            e_info = sys.exc_info()[1]
            try:
                self.exit()
            except Exception:
                # Any stop/exit errors will be logged inside publish().
                pass
            # Re-raise the original error
            raise e_info 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:25,代码来源:wspbus.py

示例2: read_addresses

# 需要导入模块: import os [as 别名]
# 或者: from os import exit [as 别名]
def read_addresses(address_file) -> list:
    # Check file exist
    if not os.path.exists(address_file):
        print("Error: File does not exist %s", args.address_list)
        os.exit(-1)
    with open(address_file, 'r') as f:
        address_list = [FoundationalNode(*(x.strip().split(','))) for x in f]
    # Check list of FoundationalNodes
    if len(address_list) < 1:
        print("Error: Address list is empty.\nFile is empty or incorrectly formatted.")
        os.exit(-1)
    return address_list

# Send RPC request
# Take API endpoint & request body (as dict)
# Returns JSON format reply, None if errors 
开发者ID:harmony-one,项目名称:harmony-ops,代码行数:18,代码来源:common.py

示例3: lookup_appdata_folder

# 需要导入模块: import os [as 别名]
# 或者: from os import exit [as 别名]
def lookup_appdata_folder():
    from os import path, environ
    if sys.platform == 'darwin':
        if "HOME" in environ:
            data_folder = path.join(os.environ["HOME"],
                                   "Library/Application support/",
                                   global_singleton.APPNAME) + '/'
        else:
            print("Could not find home folder")
            os.exit()

    elif 'win32' in sys.platform or 'win64' in sys.platform:
        data_folder = path.join(environ['APPDATA'], global_singleton.APPNAME) + '\\'
    else:
        data_folder = path.expanduser(path.join("~",
                                    "." + global_singleton.APPNAME + "/"))
    return data_folder 
开发者ID:AdamISZ,项目名称:CoinSwapCS,代码行数:19,代码来源:configure.py

示例4: test_use_after_fork

# 需要导入模块: import os [as 别名]
# 或者: from os import exit [as 别名]
def test_use_after_fork(self):
    c = Connection.establish(self.broker)
    pid = os.fork()
    if pid:                     # Parent
      self.assertEqual((pid, 0), os.waitpid(pid, 0))
      self.assertEqual("child", c.session().receiver("child;{create:always}").fetch().content)
    else:                       # Child
      try:
        # Can establish new connections
        s = Connection.establish(self.broker).session().sender("child;{create:always}")
        self.assertRaises(SelectorStopped, c.session) # But can't use parent connection
        s.send("child")
        os._exit(0)
      except Exception, e:
        print >>sys.stderr, "test child process error: %s" % e
        os.exit(1)
      finally: 
开发者ID:apache,项目名称:qpid-python,代码行数:19,代码来源:selector.py

示例5: start

# 需要导入模块: import os [as 别名]
# 或者: from os import exit [as 别名]
def start(self):
        """Start all services."""
        atexit.register(self._clean_exit)

        self.state = states.STARTING
        self.log('Bus STARTING')
        try:
            self.publish('start')
            self.state = states.STARTED
            self.log('Bus STARTED')
        except (KeyboardInterrupt, SystemExit):
            raise
        except:
            self.log("Shutting down due to error in start listener:",
                     level=40, traceback=True)
            e_info = sys.exc_info()[1]
            try:
                self.exit()
            except:
                # Any stop/exit errors will be logged inside publish().
                pass
            # Re-raise the original error
            raise e_info 
开发者ID:naparuba,项目名称:opsbro,代码行数:25,代码来源:wspbus.py

示例6: exit

# 需要导入模块: import os [as 别名]
# 或者: from os import exit [as 别名]
def exit(self):
        """Stop all services and prepare to exit the process."""
        exitstate = self.state
        try:
            self.stop()

            self.state = states.EXITING
            self.log('Bus EXITING')
            self.publish('exit')
            # This isn't strictly necessary, but it's better than seeing
            # "Waiting for child threads to terminate..." and then nothing.
            self.log('Bus EXITED')
        except:
            # This method is often called asynchronously (whether thread,
            # signal handler, console handler, or atexit handler), so we
            # can't just let exceptions propagate out unhandled.
            # Assume it's been logged and just die.
            os._exit(70)  # EX_SOFTWARE

        if exitstate == states.STARTING:
            # exit() was called before start() finished, possibly due to
            # Ctrl-C because a start listener got stuck. In this case,
            # we could get stuck in a loop where Ctrl-C never exits the
            # process, so we just call os.exit here.
            os._exit(70)  # EX_SOFTWARE 
开发者ID:naparuba,项目名称:opsbro,代码行数:27,代码来源:wspbus.py

示例7: main

# 需要导入模块: import os [as 别名]
# 或者: from os import exit [as 别名]
def main():
  global pid

  parser = argparse.ArgumentParser(description='Draw CC Packets from MPG2 Transport Stream file.')
  parser.add_argument('infile', help='Input filename (MPEG2 Transport Stream File)', type=str)
  parser.add_argument('-p', '--pid', help='Specify a PID of a PES known to contain closed caption info (tool will attempt to find the proper PID if not specified.).', type=int, default=-1)
  args = parser.parse_args()

  infilename = args.infile
  pid = args.pid

  if not os.path.exists(infilename):
    print 'Input filename :' + infilename + " does not exist."
    os.exit(-1)

  ts = TS(infilename)

  ts.Progress = OnProgress
  ts.OnTSPacket = OnTSPacket
  ts.OnESPacket = OnESPacket

  ts.Parse() 
开发者ID:johnoneil,项目名称:arib,代码行数:24,代码来源:ts_extract.py

示例8: main

# 需要导入模块: import os [as 别名]
# 或者: from os import exit [as 别名]
def main():

  parser = argparse.ArgumentParser(description='Draw CC Packets from MPG2 Transport Stream file.')
  parser.add_argument('infile', help='Input filename (MPEG2 Transport Stream File)', type=str)
  args = parser.parse_args()

  infilename = args.infile

  if not os.path.exists(infilename):
    print 'Input filename :' + infilename + " does not exist."
    os.exit(-1)

  ts = TS(infilename)

  ts.Progress = OnProgress
  ts.OnTSPacket = OnTSPacket
  ts.OnESPacket = OnESPacket

  ts.Parse() 
开发者ID:johnoneil,项目名称:arib,代码行数:21,代码来源:ts.py

示例9: getAuthCookie

# 需要导入模块: import os [as 别名]
# 或者: from os import exit [as 别名]
def getAuthCookie(connectiontype,nitroNSIP,nitroUser,nitroPass):
   url = '%s://%s/nitro/v1/config/login' % (connectiontype, nitroNSIP)
   headers = {'Content-type': 'application/vnd.com.citrix.netscaler.login+json'}
   json_string = {
       "login":{
       "username":nitroUser,
       "password":nitroPass,
       }
   }
   payload = json.dumps(json_string)
   try:
     response = requests.post(url, data=payload, headers=headers, verify=False, timeout=1.0)
     response.raise_for_status()      
   except requests.exceptions.RequestException as e:
     print(e)
     sys.exit(1)
   except requests.exceptions.HTTPError as err:
     print(err)
     sys.exit(1)
    
   cookie = response.cookies['NITRO_AUTH_TOKEN']
   nitroCookie = 'NITRO_AUTH_TOKEN=%s' % cookie
   return nitroCookie 
开发者ID:ryancbutler,项目名称:ns-letsencrypt,代码行数:25,代码来源:ns-copytons.py

示例10: _setup_working_path

# 需要导入模块: import os [as 别名]
# 或者: from os import exit [as 别名]
def _setup_working_path(self):
        if self.path is None:
            # work in temp folder
            temp_folder = tempfile.mkdtemp()
            os.chdir(temp_folder)
            return temp_folder
        else:
            if not os.path.isider(self.path):
                print("Given simulation path does not exist or invalid, trying to create")
                try:
                    os.mkdir(path)
                except OSError:
                    print("Failed to create given path")
                    os.exit(1)
            os.chdir(self.path)
            return self.path 
开发者ID:mcellteam,项目名称:cellblender,代码行数:18,代码来源:worker.py

示例11: start

# 需要导入模块: import os [as 别名]
# 或者: from os import exit [as 别名]
def start(self):
        """Start all services."""
        atexit.register(self._clean_exit)

        self.state = states.STARTING
        self.log('Bus STARTING')
        try:
            self.publish('start')
            self.state = states.STARTED
            self.log('Bus STARTED')
        except (KeyboardInterrupt, SystemExit):
            raise
        except:
            self.log('Shutting down due to error in start listener:',
                     level=40, traceback=True)
            e_info = sys.exc_info()[1]
            try:
                self.exit()
            except:
                # Any stop/exit errors will be logged inside publish().
                pass
            # Re-raise the original error
            raise e_info 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:25,代码来源:wspbus.py

示例12: start

# 需要导入模块: import os [as 别名]
# 或者: from os import exit [as 别名]
def start(self):
        """Start all services."""
        atexit.register(self._clean_exit)
        
        self.state = states.STARTING
        self.log('Bus STARTING')
        try:
            self.publish('start')
            self.state = states.STARTED
            self.log('Bus STARTED')
        except (KeyboardInterrupt, SystemExit):
            raise
        except:
            self.log("Shutting down due to error in start listener:",
                     level=40, traceback=True)
            e_info = sys.exc_info()[1]
            try:
                self.exit()
            except:
                # Any stop/exit errors will be logged inside publish().
                pass
            # Re-raise the original error
            raise e_info 
开发者ID:binhex,项目名称:moviegrabber,代码行数:25,代码来源:wspbus.py

示例13: exit

# 需要导入模块: import os [as 别名]
# 或者: from os import exit [as 别名]
def exit(self):
        """Stop all services and prepare to exit the process."""
        exitstate = self.state
        try:
            self.stop()
            
            self.state = states.EXITING
            self.log('Bus EXITING')
            self.publish('exit')
            # This isn't strictly necessary, but it's better than seeing
            # "Waiting for child threads to terminate..." and then nothing.
            self.log('Bus EXITED')
        except:
            # This method is often called asynchronously (whether thread,
            # signal handler, console handler, or atexit handler), so we
            # can't just let exceptions propagate out unhandled.
            # Assume it's been logged and just die.
            os._exit(70) # EX_SOFTWARE
        
        if exitstate == states.STARTING:
            # exit() was called before start() finished, possibly due to
            # Ctrl-C because a start listener got stuck. In this case,
            # we could get stuck in a loop where Ctrl-C never exits the
            # process, so we just call os.exit here.
            os._exit(70) # EX_SOFTWARE 
开发者ID:binhex,项目名称:moviegrabber,代码行数:27,代码来源:wspbus.py

示例14: __init__

# 需要导入模块: import os [as 别名]
# 或者: from os import exit [as 别名]
def __init__(self):
        """Initialize pub/sub bus."""
        self.execv = False
        self.state = states.STOPPED
        channels = 'start', 'stop', 'exit', 'graceful', 'log', 'main'
        self.listeners = dict(
            (channel, set())
            for channel in channels
        )
        self._priorities = {} 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:12,代码来源:wspbus.py

示例15: publish

# 需要导入模块: import os [as 别名]
# 或者: from os import exit [as 别名]
def publish(self, channel, *args, **kwargs):
        """Return output of all subscribers for the given channel."""
        if channel not in self.listeners:
            return []

        exc = ChannelFailures()
        output = []

        raw_items = (
            (self._priorities[(channel, listener)], listener)
            for listener in self.listeners[channel]
        )
        items = sorted(raw_items, key=operator.itemgetter(0))
        for priority, listener in items:
            try:
                output.append(listener(*args, **kwargs))
            except KeyboardInterrupt:
                raise
            except SystemExit:
                e = sys.exc_info()[1]
                # If we have previous errors ensure the exit code is non-zero
                if exc and e.code == 0:
                    e.code = 1
                raise
            except Exception:
                exc.handle_exception()
                if channel == 'log':
                    # Assume any further messages to 'log' will fail.
                    pass
                else:
                    self.log('Error in %r listener %r' % (channel, listener),
                             level=40, traceback=True)
        if exc:
            raise exc
        return output 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:37,代码来源:wspbus.py


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