python类_exit()的实例源码

cli.py 文件源码 项目:kcli 作者: karmab 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def pool(args):
    """Create/Delete pool"""
    pool = args.pool
    delete = args.delete
    full = args.delete
    pooltype = args.pooltype
    path = args.path
    global config
    k = config.k
    if delete:
        common.pprint("Deleting pool %s..." % (pool), color='green')
        k.delete_pool(name=pool, full=full)
        return
    if path is None:
        common.pprint("Missing path. Leaving...", color='red')
        os._exit(1)
    common.pprint("Adding pool %s..." % (pool), color='green')
    k.create_pool(name=pool, poolpath=path, pooltype=pooltype)
cli.py 文件源码 项目:kcli 作者: karmab 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def network(args):
    """Create/Delete/List Network"""
    name = args.name
    delete = args.delete
    isolated = args.isolated
    cidr = args.cidr
    nodhcp = args.nodhcp
    domain = args.domain
    pxe = args.pxe
    global config
    k = config.k
    if name is None:
        common.pprint("Missing Network", color='red')
        os._exit(1)
    if delete:
        result = k.delete_network(name=name)
        common.handle_response(result, name, element='Network ', action='deleted')
    else:
        if isolated:
            nat = False
        else:
            nat = True
        dhcp = not nodhcp
        result = k.create_network(name=name, cidr=cidr, dhcp=dhcp, nat=nat, domain=domain, pxe=pxe)
        common.handle_response(result, name, element='Network ')
manager.py 文件源码 项目:weibo 作者: windskyer 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def init_host(self, tg, **kwargs):
        LOG.info(_LI('Willing init  host function.......'))
        if CONF.is_all:
            pid = os.fork()
            if pid == 0:
                child_started = False
                while True:
                    enable_spawn = kwargs.get('enable_spawn', True)
                    if enable_spawn:
                        eventlet.spawn(self.get_all_user_all_weibo_info,
                                       **kwargs)
                        child_started = True
                    else:
                        kwargs['tg'] = tg
                        self.get_all_user_all_weibo_info(**kwargs)
                        child_started = True
                    if not child_started:
                        break
                os._exit(2)

            LOG.debug(_LI('Started child %d' % pid))

    # ?????? 14400s  ????4?
generator.py 文件源码 项目:OSPTF 作者: xSploited 项目源码 文件源码 阅读 47 收藏 0 点赞 0 评论 0
def generate(self):
        return textwrap.dedent("""
        import pupy, os

        if os.name == 'posix':
            pupy.infos['daemonize']=True
            if os.fork():   # launch child and...
                os._exit(0) # kill off parent
            os.setsid()
            if os.fork():   # launch child and...
                os._exit(0) # kill off parent again.
            os.umask(022)   # Don't allow others to write
            null=os.open('/dev/null', os.O_RDWR)
            for i in range(3):
                try:
                    os.dup2(null, i)
                except OSError, e:
                    if e.errno != errno.EBADF:
                        raise
            os.close(null)
        """)
Board.py 文件源码 项目:iotronic-lightning-rod 作者: openstack 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def getWampAgent(self, config):
        '''This method gets and sets the WAMP Board attributes from the conf file.

        '''
        try:

            self.wamp_config = config['iotronic']['wamp']['main-agent']
            LOG.info('WAMP Agent settings:')

        except Exception:
            if (self.status is None) | (self.status == "registered"):
                self.wamp_config = \
                    config['iotronic']['wamp']['registration-agent']
                LOG.info('Registration Agent settings:')
            else:
                LOG.error(
                    "WAMP Agent configuration is wrong... "
                    "please check settings.json WAMP configuration... Bye!"
                )
                os._exit(1)

        LOG.info(' - agent: ' + str(self.agent))
        LOG.info(' - url: ' + str(self.wamp_config['url']))
        LOG.info(' - realm: ' + str(self.wamp_config['realm']))
        # LOG.debug("- conf:\n" + json.dumps(self.wamp_config, indent=4))
worker.py 文件源码 项目:corvus-web-public 作者: eleme 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def create_daemon(task_id, version):
    pid = os.fork()
    if pid == 0:
        os.setsid()
        sub_pid = os.fork()
        if sub_pid == 0:
            try:
                run('supervisorctl restart corvus-agent:')
                for _ in range(30):
                    if program_running('corvus-agent:corvus-agent-api') and \
                            program_running('corvus-agent:corvus-agent-task'):
                        break
                    time.sleep(1)
                else:
                    raise TaskException('Agent updated but not running')
                Task.set_status(task_id, Task.DONE)
            except Exception:
                Task.set_status(task_id, Task.FAILED,
                                reason=traceback.format_exc())
            exit(0)
        else:
            os._exit(0)
    else:
        os._exit(0)
host.py 文件源码 项目:masakari-monitors 作者: openstack 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def init_host(self):
        """Initialization for hostmonitor."""
        try:
            # Determine dynamic load driver from configuration.
            driver_name = CONF.host.monitoring_driver

            # Load the driver to global.
            self.driver = driver.DriverManager(
                namespace='hostmonitor.driver',
                name=driver_name,
                invoke_on_load=True,
                invoke_args=(),
            )
        except Exception as e:
            LOG.exception(
                "Exception caught during initializing hostmonitor: %s", e)
            os._exit(1)
163down.py 文件源码 项目:163mooc_dumper 作者: wsdzl 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def main():
    if len(sys.argv) == 1:
        if os.path.isfile('tmp_url.txt'):
            with open('tmp_url.txt') as f:
                url = f.read()
        else:
            url = input('URL: ')
    else:
        url = sys.argv[1]
    with open('tmp_url.txt', 'w') as f:
        f.write(url)
    name, videos = parse_videos(url)
    length = len(videos)
    if not os.path.isdir(name): os.makedirs(name)
    for i in range(length):
        try:
            download(videos, i, name, length)
        except KeyboardInterrupt:
            os._exit(1)
    if os.path.isfile('tmp_url.txt'):
        os.unlink('tmp_url.txt')
daemonizer.py 文件源码 项目:SameKeyProxy 作者: xzhou 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def become_daemon(self, root_dir='/'):
        if os.fork() != 0:  # launch child and ...
            os._exit(0)  # kill off parent
        os.setsid()
        os.chdir(root_dir)
        os.umask(0)
        if os.fork() != 0: # fork again so we are not a session leader
            os._exit(0)
        sys.stdin.close()
        sys.__stdin__ = sys.stdin
        sys.stdout.close()
        sys.stdout = sys.__stdout__ = _NullDevice()
        sys.stderr.close()
        sys.stderr = sys.__stderr__ = _NullDevice()
        for fd in range(1024):
            try:
                os.close(fd)
            except OSError:
                pass
no-color-airscript-ng.py 文件源码 项目:Airscript-ng 作者: Sh3llcod3 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def gitdeps():
    import subprocess
    call = subprocess.call
    if call("ls ~/.airscriptNG/air 2>/dev/null >/dev/null",shell=True) != 0:
        if call('/usr/bin/env ping -c1 8.8.8.8 >/dev/null 2>/dev/null',shell=True) == 0:
            call("mkdir -p ~/.airscriptNG/air && cd ~/.airscriptNG/air && apt update --allow-unauthenticated && apt install git git-core libnl-3-dev openssl libnl*-gen* libgcrypt20-dev build-essential libssl-dev -y --allow-unauthenticated && git clone git://git.kali.org/packages/aircrack-ng.git -b upstream && cd * && make gcrypt=true",shell=True)
        else:
            print('\n%s[-]%s Failed to install inital dependancies, please connect to the internet and try again\n' %(col.fail,col.endl))
            os._exit(1)
    if call("ls ~/.airscriptNG/wps 2>/dev/null >/dev/null",shell=True) != 0:
        if call('/usr/bin/env ping -c1 8.8.8.8 >/dev/null 2>/dev/null',shell=True) == 0:
            call("mkdir -p ~/.airscriptNG/wps && cd ~/.airscriptNG/wps && apt update --allow-unauthenticated && apt install libpcap-dev build-essential -y --allow-unauthenticated && git clone git://git.kali.org/packages/reaver.git -b upstream && cd */src && ./configure && make",shell=True)
        else:
            print('\n%s[-]%s Failed to install inital dependancies, please connect to the internet and try again\n' %(col.fail,col.endl))
            os._exit(1)
    if call("ls ~/.airscriptNG/magic 2>/dev/null >/dev/null",shell=True) != 0:
        if call('/usr/bin/env ping -c1 8.8.8.8 >/dev/null 2>/dev/null',shell=True) == 0:
            call("mkdir -p ~/.airscriptNG/magic && cd ~/.airscriptNG/magic && apt update --allow-unauthenticated && apt install libssl-dev build-essential -y --allow-unauthenticated && git clone git://git.kali.org/packages/pixiewps.git -b upstream && cd */src/ && make && make install",shell=True)
        else:
            print('\n%s[-]%s Failed to install inital dependancies, please connect to the internet and try again\n' %(col.fail,col.endl))
            os._exit(1)
airscript-ng.py 文件源码 项目:Airscript-ng 作者: Sh3llcod3 项目源码 文件源码 阅读 46 收藏 0 点赞 0 评论 0
def gitdeps():
    import subprocess
    call = subprocess.call
    if call("ls ~/.airscriptNG/air 2>/dev/null >/dev/null",shell=True) != 0:
        if call('/usr/bin/env ping -c1 8.8.8.8 >/dev/null 2>/dev/null',shell=True) == 0:
            call("mkdir -p ~/.airscriptNG/air && cd ~/.airscriptNG/air && apt update --allow-unauthenticated && apt install git git-core libnl-3-dev openssl libnl*-gen* libgcrypt20-dev build-essential libssl-dev -y --allow-unauthenticated && git clone git://git.kali.org/packages/aircrack-ng.git -b upstream && cd * && make gcrypt=true",shell=True)
        else:
            print('\n%s[-]%s Failed to install inital dependancies, please connect to the internet and try again\n' %(col.fail,col.endl))
            os._exit(1)
    if call("ls ~/.airscriptNG/wps 2>/dev/null >/dev/null",shell=True) != 0:
        if call('/usr/bin/env ping -c1 8.8.8.8 >/dev/null 2>/dev/null',shell=True) == 0:
            call("mkdir -p ~/.airscriptNG/wps && cd ~/.airscriptNG/wps && apt update --allow-unauthenticated && apt install libpcap-dev build-essential -y --allow-unauthenticated && git clone git://git.kali.org/packages/reaver.git -b upstream && cd */src && ./configure && make",shell=True)
        else:
            print('\n%s[-]%s Failed to install inital dependancies, please connect to the internet and try again\n' %(col.fail,col.endl))
            os._exit(1)
    if call("ls ~/.airscriptNG/magic 2>/dev/null >/dev/null",shell=True) != 0:
        if call('/usr/bin/env ping -c1 8.8.8.8 >/dev/null 2>/dev/null',shell=True) == 0:
            call("mkdir -p ~/.airscriptNG/magic && cd ~/.airscriptNG/magic && apt update --allow-unauthenticated && apt install libssl-dev build-essential -y --allow-unauthenticated && git clone git://git.kali.org/packages/pixiewps.git -b upstream && cd */src/ && make && make install",shell=True)
        else:
            print('\n%s[-]%s Failed to install inital dependancies, please connect to the internet and try again\n' %(col.fail,col.endl))
            os._exit(1)
transform_service.py 文件源码 项目:monasca-transform 作者: openstack 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def shutdown_all_threads_and_die():
    """Shut down all threads and exit process.
    Hit it with a hammer to kill all threads and die.
    """
    LOG = log.getLogger(__name__)
    LOG.info('Monasca Transform service stopping...')
    os._exit(1)
libmilter.py 文件源码 项目:sipxecs-voicemail-transcription 作者: andrewsauder 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def start(self):
        # Fork and run
        if not os.fork():
            self.run()
            os._exit(0)
        else:
            return
qiushimm.py 文件源码 项目:Python 作者: Guzi219 项目源码 文件源码 阅读 54 收藏 0 点赞 0 评论 0
def SaveTotalPageToFile(self, new_page_num):

        print '====================save the totalpage to totalpage.ini===================='

        file = INIFILE('totalpage.ini')

        # must write something if you set is_write to true. otherwise your file become empty.
        is_ok = file.Init(True, True)
        if not is_ok:
            print 'class initializing failed. check the [%s] file first.' % ('totalpage.ini')
            os._exit(0)

        old_page_num = file.GetValue('Main', 'totalpage')
        print '====================the old_page_num is [%s], the new_page_num is [%s]====================' % (old_page_num, new_page_num)
        file.SetValue('Main', 'totalpage', new_page_num)
        #close all
        file.UnInit()

        if int(new_page_num) >= int(old_page_num): #if there is new page
            self.unload_page_num = int(new_page_num) - int(old_page_num)
            if self.unload_page_num == 0:   #?????????????
               self.unload_page_num = 1
            elif self.unload_page_num > 0: #??????????????????????
                self.unload_page_num += 1
            print 'Ok, we got %s pages to load.' %(self.unload_page_num)
        else: #nothing new, stop main thread
            print 'Oops! Nothing new. exit main thread now.'
            os._exit(0) #terminal sub thread
            self.enable = False #terminal main thread

    # ????????
qiubaiadult.py 文件源码 项目:Python 作者: Guzi219 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def SaveTotalPageToFile(self, new_page_num):

        print '====================save the totalpage to totalpage.ini===================='

        file = INIFILE('qiubaiadult_page.ini')

        # must write something if you set is_write to true. otherwise your file become empty.
        is_ok = file.Init(True, True)
        if not is_ok:
            print 'class initializing failed. check the [%s] file first.' % ('totalpage.ini')
            os._exit(0)

        old_page_num = file.GetValue('Main', 'totalpage')
        print '====================the old_page_num is [%s], the new_page_num is [%s]====================' % (old_page_num, new_page_num)
        file.SetValue('Main', 'totalpage', new_page_num)
        #close all
        file.UnInit()

        if int(new_page_num) >= int(old_page_num): #if there is new page
            # self.unload_page_num = int(new_page_num) - int(old_page_num)
            self.unload_page_num = int(new_page_num) - int(old_page_num)
            if self.unload_page_num == 0:   #?????????????
               self.unload_page_num = 1
            elif self.unload_page_num > 0: #??????????????????????***?????????
               self.unload_page_num += 1
            print 'since we start at page %s, we still got (%s-%s) pages to load.' %(self.page, self.unload_page_num, self.page)
        else: #nothing new, stop main thread
            print 'Oops! Nothing new. exit main thread now.'
            os._exit(0) #terminal sub thread
            self.enable = False #terminal main thread

    # ????????
daemon.py 文件源码 项目:amadash 作者: ipartola 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def daemonize(double_fork=True):
    '''Puts process in the background using usual UNIX best practices.'''

    try:
        os.umask(0o22)
    except Exception as e:
        raise Exception("Unable to change file creation mask: %s" % e)

    os.chdir('/')

    # First fork
    if double_fork:
        try:
            pid = os.fork()
            if pid > 0:
                os._exit(0)
        except OSError as e:
            raise Exception("Error on first fork: [%d] %s" % (e.errno, e.strerr,))

    os.setsid()

    # Second fork
    try:
        pid = os.fork()
        if pid > 0:
            os._exit(0)
    except OSError as e:
        raise Exception("Error on second fork: [%d] %s" % (e.errno, e.strerr,))

    close_open_files()
    os.dup2(os.open(os.devnull, os.O_RDWR), sys.stdin.fileno())
    os.dup2(os.open(os.devnull, os.O_RDWR), sys.stdout.fileno())
    os.dup2(os.open(os.devnull, os.O_RDWR), sys.stderr.fileno())
detector.py 文件源码 项目:amadash 作者: ipartola 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def handle_button_traffic(self, mac, eth_protocol):
        button = self.buttons.get(mac)
        if not button:
            return

        now = time.time()
        time_delta = now - button['last_seen']
        button['last_seen'] = now
        if time_delta < options.main.button_timeout:
            return

        logging.getLogger().info('Button press detected: {} [{}].'.format(button['name'], button['mac']))
        action = button['action']
        env = dict(os.environ)
        env.update({
            'BUTTON_NAME': button['name'],
            'BUTTON_MAC': button['mac'],
        })

        pid = None
        try:
            pid = os.fork()
        except OSError as e:
            logging.getLogger().info("Could not fork for action: [{}] {}".format(e.errno, e.strerr))

        if pid == 0:
            daemonize(False)
            subprocess.Popen(action, shell=True, env=env).wait()
            os._exit(0)


问题


面经


文章

微信
公众号

扫码关注公众号