當前位置: 首頁>>代碼示例>>Python>>正文


Python os.abort方法代碼示例

本文整理匯總了Python中os.abort方法的典型用法代碼示例。如果您正苦於以下問題:Python os.abort方法的具體用法?Python os.abort怎麽用?Python os.abort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在os的用法示例。


在下文中一共展示了os.abort方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: update_collection_set

# 需要導入模塊: import os [as 別名]
# 或者: from os import abort [as 別名]
def update_collection_set(cls, item, response ,spider):
        # if cls.entry == "COLLECTION":
        cls.collection_set.add(item["pid"].split('_')[0])
        cls.process = len(cls.collection_set) - cls.init_colletion_set_size
        # for debug only
        if cls.process > cls.maxsize:
            if cls.entry == "COLLECTION":
                with open("./.trace", "wb") as f:
                    pickle.dump(cls.collection_set, f)

            # store .json file
            f = open("data_{0}.json".format('_'.join(cf.get('SRH', 'TAGS').split(" "))), 'w')
            data = [item.__dict__() for item in cls.data]
            json.dump(data, f)

            print("Crawling complete, got {0} data".format(len(cls.data)))
            f.close()
            os.abort()
            # raise CloseSpider
            # cls.signalManger.send_catch_log(signal=signals.spider_closed) 
開發者ID:vicety,項目名稱:Pixiv-Crawler,代碼行數:22,代碼來源:pixiv-beta.py

示例2: mem_check

# 需要導入模塊: import os [as 別名]
# 或者: from os import abort [as 別名]
def mem_check(opts):

    while True:

        if opts['gc']:
            try:
                gc.collect()
            except Exception as e:
                logging.exception(repr(e) + ' while gc.collect()')

        try:
            rss = psutil.Process(os.getpid()).memory_info().rss

            logging.info('current memory used: {rss}'.format(rss=rss))

            if rss > opts['threshold']:
                memory_dump(opts)
                os.abort()
        except Exception as e:
            logging.exception(repr(e) + ' while checking memory usage')

        finally:
            time.sleep(opts['interval']) 
開發者ID:bsc-s2,項目名稱:pykit,代碼行數:25,代碼來源:profiling.py

示例3: _do_main

# 需要導入模塊: import os [as 別名]
# 或者: from os import abort [as 別名]
def _do_main(self, commands):
        """
        :type commands: list of VSCtlCommand
        """
        self._reset()
        self._init_schema_helper()
        self._run_prerequisites(commands)

        idl_ = idl.Idl(self.remote, self.schema_helper)
        seqno = idl_.change_seqno
        while True:
            self._idl_wait(idl_, seqno)

            seqno = idl_.change_seqno
            if self._do_vsctl(idl_, commands):
                break

            if self.txn:
                self.txn.abort()
                self.txn = None
            # TODO:XXX
            # ovsdb_symbol_table_destroy(symtab)

        idl_.close() 
開發者ID:OpenState-SDN,項目名稱:ryu,代碼行數:26,代碼來源:vsctl.py

示例4: execute

# 需要導入模塊: import os [as 別名]
# 或者: from os import abort [as 別名]
def execute(self, key):
        file = "data%d" % numpy.random.randint(1, 1000)
        odb = "%s.odb" % file
        context.tmp.append(odb)
        cmd = (
            'odbsql -q "'
            + self.args["query"]
            + '" -i '
            + self.args["path"]
            + " -f newodb -o "
            + odb
        )
        print(cmd)
        if os.system(cmd):
            print("Error in filtering ODB data... Aborting")
            os.abort()
        Magics.setc("odb_filename", odb) 
開發者ID:ecmwf,項目名稱:magics-python,代碼行數:19,代碼來源:macro.py

示例5: test_run_abort

# 需要導入模塊: import os [as 別名]
# 或者: from os import abort [as 別名]
def test_run_abort(self):
        # returncode handles signal termination
        with support.SuppressCrashReport():
            p = subprocess.Popen([sys.executable, "-c",
                                  'import os; os.abort()'])
            p.wait()
        self.assertEqual(-p.returncode, signal.SIGABRT) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:9,代碼來源:test_subprocess.py

示例6: _async_terminate

# 需要導入模塊: import os [as 別名]
# 或者: from os import abort [as 別名]
def _async_terminate(*_):
  async_quit()
  global _num_terminate_requests
  _num_terminate_requests += 1
  if _num_terminate_requests == 1:
    logging.info('Shutting down.')
  if _num_terminate_requests >= 3:
    logging.error('Received third interrupt signal. Terminating.')
    os.abort() 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:11,代碼來源:shutdown.py

示例7: setUp

# 需要導入模塊: import os [as 別名]
# 或者: from os import abort [as 別名]
def setUp(self):
    self.mox = mox.Mox()
    self.mox.StubOutWithMock(os, 'abort')
    shutdown._shutting_down = False
    shutdown._num_terminate_requests = 0
    self._sigint_handler = signal.getsignal(signal.SIGINT)
    self._sigterm_handler = signal.getsignal(signal.SIGTERM) 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:9,代碼來源:shutdown_test.py

示例8: test_async_terminate_abort

# 需要導入模塊: import os [as 別名]
# 或者: from os import abort [as 別名]
def test_async_terminate_abort(self):
    os.abort()
    self.mox.ReplayAll()
    shutdown._async_terminate()
    self.assertTrue(shutdown._shutting_down)
    shutdown._async_terminate()
    shutdown._async_terminate()
    self.mox.VerifyAll() 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:10,代碼來源:shutdown_test.py

示例9: test_run_abort

# 需要導入模塊: import os [as 別名]
# 或者: from os import abort [as 別名]
def test_run_abort(self):
        # returncode handles signal termination
        with _SuppressCoreFiles():
            p = subprocess.Popen([sys.executable, "-c",
                                  "import os; os.abort()"])
            p.wait()
        self.assertEqual(-p.returncode, signal.SIGABRT) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:9,代碼來源:test_subprocess.py

示例10: test_os_abort

# 需要導入模塊: import os [as 別名]
# 或者: from os import abort [as 別名]
def test_os_abort(self):
        # Positive
        self.TestCommandLine(("-c", "import os; os.abort()"), "", 1)
        self.TestScript((), "import os\nos.abort()", "", 1) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:6,代碼來源:test_stdconsole.py

示例11: __start

# 需要導入模塊: import os [as 別名]
# 或者: from os import abort [as 別名]
def __start(self):
        "do work of starting the process"
        self.statusPipe = _StatusPipe()
        self.started = True  # do first to prevent restarts on error
        self.pid = os.fork()
        if self.pid == 0:
            try:
                self.__childStart()
            finally:
                os.abort() # should never make it here
        else:
            self.__parentStart() 
開發者ID:ComparativeGenomicsToolkit,項目名稱:Comparative-Annotation-Toolkit,代碼行數:14,代碼來源:pipeline.py

示例12: start_mem_check_thread

# 需要導入模塊: import os [as 別名]
# 或者: from os import abort [as 別名]
def start_mem_check_thread(threshold=1024 * 1024 * 1024,
                           gc=False,
                           size_range=None,
                           interval=1
                           ):
    """
    Start a thread in background and in daemon mode, to watch memory usage.
    If memory this process is using beyond `threshold`, a memory usage profile
    is made and is written to root logger. And process is aborted.

    `threshold`:    maximum memory a process can use before abort.
    `gc`:           whether to run gc every time before checking memory usage.
    `size_range`:   in tuple, dump only object of size in this range.
    `interval`:     memory check interval.
    """

    options = {
        'threshold': threshold,
        'gc': gc,
        'size_range': size_range,
        'interval': interval,
    }

    th = threading.Thread(target=mem_check, args=(options,))
    th.daemon = True
    th.start()

    return th 
開發者ID:bsc-s2,項目名稱:pykit,代碼行數:30,代碼來源:profiling.py

示例13: sync_virtualchain

# 需要導入模塊: import os [as 別名]
# 或者: from os import abort [as 別名]
def sync_virtualchain(blockchain_opts, last_block, state_engine, expected_snapshots={}, tx_filter=None ):
    """
    Synchronize the virtual blockchain state up until a given block.

    Obtain the operation sequence from the blockchain, up to and including last_block.
    That is, go and fetch each block we haven't seen since the last call to this method,
    extract the operations from them, and record in the given working_dir where we left
    off while watching the blockchain.

    Store the state engine state, consensus snapshots, and last block to the working directory.
    Return True on success
    Return False if we're supposed to stop indexing
    Abort the program on error.  The implementation should catch timeouts and connection errors
    """

    rc = False
    start = datetime.datetime.now()
    while True:
        try:

            # advance state
            rc = indexer.StateEngine.build(blockchain_opts, last_block + 1, state_engine, expected_snapshots=expected_snapshots, tx_filter=tx_filter )
            break
        
        except Exception, e:
            log.exception(e)
            log.error("Failed to synchronize chain; exiting to safety")
            os.abort() 
開發者ID:blockstack,項目名稱:virtualchain,代碼行數:30,代碼來源:virtualchain.py

示例14: db_query_execute

# 需要導入模塊: import os [as 別名]
# 或者: from os import abort [as 別名]
def db_query_execute(cls, cur, query, values, verbose=True):
        """
        Execute a query.
        Handle db timeouts.
        Abort on failure.
        """
        timeout = 1.0

        if verbose:
            log.debug(cls.db_format_query(query, values))

        while True:
            try:
                ret = cur.execute(query, values)
                return ret
            except sqlite3.OperationalError as oe:
                if oe.message == "database is locked":
                    timeout = timeout * 2 + timeout * random.random()
                    log.error("Query timed out due to lock; retrying in %s: %s" % (timeout, cls.db_format_query( query, values )))
                    time.sleep(timeout)
                
                else:
                    log.exception(oe)
                    log.error("FATAL: failed to execute query (%s, %s)" % (query, values))
                    log.error("\n".join(traceback.format_stack()))
                    os.abort()

            except Exception, e:
                log.exception(e)
                log.error("FATAL: failed to execute query (%s, %s)" % (query, values))
                log.error("\n".join(traceback.format_stack()))
                os.abort() 
開發者ID:blockstack,項目名稱:virtualchain,代碼行數:34,代碼來源:indexer.py

示例15: not_reached

# 需要導入模塊: import os [as 別名]
# 或者: from os import abort [as 別名]
def not_reached():
    os.abort() 
開發者ID:OpenState-SDN,項目名稱:ryu,代碼行數:4,代碼來源:vsctl.py


注:本文中的os.abort方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。