Python os.abort() Examples

The following are code examples for showing how to use os.abort(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: deb-ryu   Author: openstack   File: vsctl.py    Apache License 2.0 6 votes vote down vote up
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() 
Example 2
Project: Pixiv-Crawler   Author: vicety   File: pixiv-beta.py    GNU General Public License v3.0 6 votes vote down vote up
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) 
Example 3
Project: pykit   Author: bsc-s2   File: profiling.py    MIT License 6 votes vote down vote up
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']) 
Example 4
Project: emulated-sdn-application   Author: tranlyvu   File: vsctl.py    Apache License 2.0 6 votes vote down vote up
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() 
Example 5
Project: empower-ryu   Author: clicknf   File: vsctl.py    Apache License 2.0 6 votes vote down vote up
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() 
Example 6
Project: ryu-lagopus-ext   Author: lagopus   File: vsctl.py    Apache License 2.0 6 votes vote down vote up
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() 
Example 7
Project: IPViewer   Author: gauravssnl   File: ipviewer.py    Apache License 2.0 6 votes vote down vote up
def app(self):
        appuifw.app.title=ru(title)
        appuifw.app.exit_key_handler=self.exit
        self.i=1
        self.console=Console.Console(True)
        self.text=self.console.text
        appuifw.app.body=self.console.text
        self.text.color=255,0,0
        self.text.font= "title",20
        self.write("%s by %s"%(title,self.developer))
        self.text.color=0,0,0
        self.text.font= "title",18
        if  not len(socket.access_points()):
            self.write("No Access Point is defined.Please add new APN.App will exit")
            e32.ao_sleep(2)
            os.abort()
        else:
            pass    
        self.write("Access Point: %s"%self.ap_list[self.apid_list.index(self.sets.APN)])
        self.write("Find IP:%s"%self.insta(self.sets.IPHUNT))
        self.write("Run Simple Server: %s"%self.yesno[self.sets.RUNSS])
        appuifw.app.menu=[(ru("Start"),self.start),(ru("Settings"),self.settings),(ru("About"),self.about),(ru("Exit"),self.exit)] 
Example 8
Project: magics-python   Author: ecmwf   File: macro.py    Apache License 2.0 6 votes vote down vote up
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) 
Example 9
Project: Ryu-Qos   Author: xiaobinglu   File: vsctl.py    Apache License 2.0 6 votes vote down vote up
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() 
Example 10
Project: ops   Author: bsc-s2   File: profiling.py    MIT License 6 votes vote down vote up
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']) 
Example 11
Project: SDN-QoS-Routing   Author: dodoyuan   File: vsctl.py    Apache License 2.0 6 votes vote down vote up
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() 
Example 12
Project: pyblish-win   Author: pyblish   File: test_subprocess.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
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) 
Example 13
Project: NiujiaoDebugger   Author: MrSrc   File: test_subprocess.py    GNU General Public License v3.0 5 votes vote down vote up
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) 
Example 14
Project: ironpython2   Author: IronLanguages   File: test_subprocess.py    Apache License 2.0 5 votes vote down vote up
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) 
Example 15
Project: ironpython2   Author: IronLanguages   File: test_stdconsole.py    Apache License 2.0 5 votes vote down vote up
def test_os_abort(self):
        # Positive
        self.TestCommandLine(("-c", "import os; os.abort()"), "", 1)
        self.TestScript((), "import os\nos.abort()", "", 1) 
Example 16
Project: how-to-cython-mt2   Author: martysama0134   File: test_libcython_in_gdb.py    MIT License 5 votes vote down vote up
def test_abort(self):
        gdb.execute("set args -c 'import os; os.abort()'")
        output = gdb.execute('cy run', to_string=True)
        assert 'abort' in output.lower() 
Example 17
Project: deb-ryu   Author: openstack   File: vsctl.py    Apache License 2.0 5 votes vote down vote up
def not_reached():
    os.abort() 
Example 18
Project: Comparative-Annotation-Toolkit   Author: ComparativeGenomicsToolkit   File: pipeline.py    Apache License 2.0 5 votes vote down vote up
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() 
Example 19
Project: cqp-sdk-for-py37-native   Author: crud-boy   File: test_subprocess.py    GNU General Public License v2.0 5 votes vote down vote up
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) 
Example 20
Project: ableton-live-webapi   Author: valsteen   File: test_libcython_in_gdb.py    The Unlicense 5 votes vote down vote up
def test_abort(self):
        gdb.execute("set args -c 'import os; os.abort()'")
        output = gdb.execute('cy run', to_string=True)
        assert 'abort' in output.lower() 
Example 21
Project: oss-ftp   Author: aliyun   File: test_subprocess.py    MIT License 5 votes vote down vote up
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) 
Example 22
Project: pykit   Author: bsc-s2   File: profiling.py    MIT License 5 votes vote down vote up
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 
Example 23
Project: Bitly-Symbian   Author: gauravssnl   File: default.py    Apache License 2.0 5 votes vote down vote up
def exit():
    os.abort() 
Example 24
Project: emulated-sdn-application   Author: tranlyvu   File: vsctl.py    Apache License 2.0 5 votes vote down vote up
def not_reached():
    os.abort() 
Example 25
Project: empower-ryu   Author: clicknf   File: vsctl.py    Apache License 2.0 5 votes vote down vote up
def not_reached():
    os.abort() 
Example 26
Project: virtualchain   Author: blockstack   File: virtualchain.py    GNU General Public License v3.0 5 votes vote down vote up
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() 
Example 27
Project: virtualchain   Author: blockstack   File: indexer.py    GNU General Public License v3.0 5 votes vote down vote up
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() 
Example 28
Project: ryu-lagopus-ext   Author: lagopus   File: vsctl.py    Apache License 2.0 5 votes vote down vote up
def not_reached():
    os.abort() 
Example 29
Project: IPViewer   Author: gauravssnl   File: ipviewer.py    Apache License 2.0 5 votes vote down vote up
def exit(self):
        
        q=appuifw.query(u"Do you really want to Exit","query")
        if q:
            try:
                self.timerip.cancel()
                self.timert.cancel()
                appuifw.app.set_exit()
            except:
                os.abort() 
Example 30
Project: kodiekar   Author: iivvoo   File: rpdb2.py    MIT License 5 votes vote down vote up
def _atexit(fabort = False):
    if g_fignore_atexit:
        return

    print_debug("Entered _atexit() in pid %d" % _getpid())

    if g_debugger is None:
        return

    if not fabort:
        g_debugger.stoptrace()
        
    g_debugger.send_event_exit()

    time.sleep(1.0)

    g_server.shutdown()
    g_debugger.shutdown()

    if not fabort:
        return

    if hasattr(os, 'kill') and hasattr(signal, 'SIGKILL'):
        os.kill(os.getpid(), signal.SIGKILL)
    else:
        os.abort() 
Example 31
Project: kodiekar   Author: iivvoo   File: rpdb2.py    MIT License 5 votes vote down vote up
def _atexit(fabort = False):
    if g_fignore_atexit:
        return

    print_debug("Entered _atexit() in pid %d" % _getpid())

    if g_debugger is None:
        return

    if not fabort:
        g_debugger.stoptrace()
        
    g_debugger.send_event_exit()

    time.sleep(1.0)

    g_server.shutdown()
    g_debugger.shutdown()

    if not fabort:
        return

    if hasattr(os, 'kill') and hasattr(signal, 'SIGKILL'):
        os.kill(os.getpid(), signal.SIGKILL)
    else:
        os.abort() 
Example 32
Project: Hot   Author: dsolimando   File: test_subprocess.py    GNU General Public License v3.0 5 votes vote down vote up
def test_run_abort(self):
            # returncode handles signal termination
            old_limit = self._suppress_core_files()
            try:
                p = subprocess.Popen([sys.executable,
                                      "-c", "import os; os.abort()"])
            finally:
                self._unsuppress_core_files(old_limit)
            p.wait()
            self.assertEqual(-p.returncode, signal.SIGABRT) 
Example 33
Project: magics-python   Author: ecmwf   File: macro.py    Apache License 2.0 5 votes vote down vote up
def inspect(self):
        cmd = (
            'odbsql -q "'
            + self.args["query"]
            + '" -i '
            + self.args["path"]
            + " -o data.ascii"
        )
        if os.system(cmd):
            print("Error in filtering ODB data... Aborting")
            os.abort()
        cmd = os.environ["ODB_REPORTER"] + " %s" % "data.ascii"
        if os.system(cmd):
            print("Error in viewing ODB data... Aborting")
            os.abort() 
Example 34
Project: Ryu-Qos   Author: xiaobinglu   File: vsctl.py    Apache License 2.0 5 votes vote down vote up
def not_reached():
    os.abort() 
Example 35
Project: pyCuT   Author: ceccopierangiolieugenio   File: CuWidget.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
		if not CuHelper.app_initialized():
			# Abort:
			#  i.e.
			#    QWidget: Must construct a QApplication before a QWidget
			print(self.__class__.__name__ + ": Must construct a CuApplication before a CuWidget")
			os.abort()

		self._extra = {
				'maxw' : 100000,
				'maxh' : 100000,
				'minw' : 0,
				'minh' : 0,
			}
		self._data = {}

		self._data['parent'] = kwargs.get('parent', None )
		self._data['name'] = kwargs.get('name', '')
		self._data['pos'] = CuPoint(kwargs.get('x', 0), kwargs.get('y', 0))
		self._data['size'] = CuSize(kwargs.get('w', CuHelper.getW()), kwargs.get('h', CuHelper.getH()))


		if self._data['parent'] is None:
			CuHelper.setMainWidget(self)

		self._data['childs'] = []
		self._data['win'] = CuWrapper.newWin(self, self._data['pos'].x(), self._data['pos'].y(), self._data['size'].width(), self._data['size'].height())
		self._data['layout'] = None
		self._data['mouse'] = {'underMouse':False}
		self._data['focus'] = False
		self._data['focus_policy'] = CuT.NoFocus
		self.hide() 
Example 36
Project: pyCuT   Author: ceccopierangiolieugenio   File: CuWidget.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
		if not CuHelper.app_initialized():
			# Abort:
			#  i.e.
			#    QWidget: Must construct a QApplication before a QWidget
			print(self.__class__.__name__ + ": Must construct a CuApplication before a CuWidget")
			os.abort()

		self._extra = {
				'maxw' : 100000,
				'maxh' : 100000,
				'minw' : 0,
				'minh' : 0,
			}
		self._data = {}

		self._data['parent'] = kwargs.get('parent', None )
		self._data['name'] = kwargs.get('name', '')
		self._data['pos'] = CuPoint(kwargs.get('x', 0), kwargs.get('y', 0))
		self._data['size'] = CuSize(kwargs.get('w', CuHelper.getW()), kwargs.get('h', CuHelper.getH()))


		if self._data['parent'] is None:
			CuHelper.setMainWidget(self)

		self._data['childs'] = []
		self._data['win'] = CuWrapper.newWin(self, self._data['pos'].x(), self._data['pos'].y(), self._data['size'].width(), self._data['size'].height())
		self._data['layout'] = None
		self._data['mouse'] = {'underMouse':False}
		self._data['focus'] = False
		self._data['focus_policy'] = CuT.NoFocus
		self.hide() 
Example 37
Project: pyCuT   Author: ceccopierangiolieugenio   File: CuWidget.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
		if not CuHelper.app_initialized():
			# Abort:
			#  i.e.
			#    QWidget: Must construct a QApplication before a QWidget
			print(self.__class__.__name__ + ": Must construct a CuApplication before a CuWidget")
			os.abort()

		self._extra = {
				'maxw' : 100000,
				'maxh' : 100000,
				'minw' : 0,
				'minh' : 0,
			}
		self._data = {}

		self._data['parent'] = kwargs.get('parent', None )
		self._data['name'] = kwargs.get('name', '')
		self._data['pos'] = CuPoint(kwargs.get('x', 0), kwargs.get('y', 0))
		self._data['size'] = CuSize(kwargs.get('w', CuHelper.getW()), kwargs.get('h', CuHelper.getH()))


		if self._data['parent'] is None:
			CuHelper.setMainWidget(self)

		self._data['childs'] = []
		self._data['win'] = CuWrapper.newWin(self, self._data['pos'].x(), self._data['pos'].y(), self._data['size'].width(), self._data['size'].height())
		self._data['layout'] = None
		self._data['mouse'] = {'underMouse':False}
		self._data['focus'] = False
		self._data['focus_policy'] = CuT.NoFocus
		self.hide() 
Example 38
Project: pyCuT   Author: ceccopierangiolieugenio   File: CuWidget.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
		if not CuHelper.app_initialized():
			# Abort:
			#  i.e.
			#    QWidget: Must construct a QApplication before a QWidget
			print(self.__class__.__name__ + ": Must construct a CuApplication before a CuWidget")
			os.abort()

		self._extra = {
				'maxw' : 100000,
				'maxh' : 100000,
				'minw' : 0,
				'minh' : 0,
			}
		self._data = {}

		self._data['parent'] = kwargs.get('parent', None )
		self._data['name'] = kwargs.get('name', '')
		self._data['pos'] = CuPoint(kwargs.get('x', 0), kwargs.get('y', 0))
		self._data['size'] = CuSize(kwargs.get('w', CuHelper.getW()), kwargs.get('h', CuHelper.getH()))


		if self._data['parent'] is None:
			CuHelper.setMainWidget(self)

		self._data['childs'] = []
		self._data['win'] = CuWrapper.newWin(self, self._data['pos'].x(), self._data['pos'].y(), self._data['size'].width(), self._data['size'].height())
		self._data['layout'] = None
		self._data['mouse'] = {'underMouse':False}
		self._data['focus'] = False
		self._data['focus_policy'] = CuT.NoFocus
		self.hide() 
Example 39
Project: entrance   Author: ensoft   File: ssh.py    MIT License 5 votes vote down vote up
def __init__(self, *args, **kwargs):
            print('\n\n\n\n* To use router features, re-install depending',
                  'on the package\n* name "entrance[with-router-features]",',
                  'not simply "entrance".\n* This installation does not',
                  'have the required dependencies.\n\n\n', file=sys.stderr)
            os.abort() 
Example 40
Project: ops   Author: bsc-s2   File: profiling.py    MIT License 5 votes vote down vote up
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 
Example 41
Project: PYPIC   Author: max614   File: test_libcython_in_gdb.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_abort(self):
        gdb.execute("set args -c 'import os; os.abort()'")
        output = gdb.execute('cy run', to_string=True)
        assert 'abort' in output.lower() 
Example 42
Project: abseil-py   Author: abseil   File: __init__.py    Apache License 2.0 5 votes vote down vote up
def emit(self, record):
    """Prints a record out to some streams.

    If FLAGS.logtostderr is set, it will print to sys.stderr ONLY.
    If FLAGS.alsologtostderr is set, it will print to sys.stderr.
    If FLAGS.logtostderr is not set, it will log to the stream
      associated with the current thread.

    Args:
      record: logging.LogRecord, the record to emit.
    """
    # People occasionally call logging functions at import time before
    # our flags may have even been defined yet, let alone even parsed, as we
    # rely on the C++ side to define some flags for us and app init to
    # deal with parsing.  Match the C++ library behavior of notify and emit
    # such messages to stderr.  It encourages people to clean-up and does
    # not hide the message.
    level = record.levelno
    if not FLAGS.is_parsed():  # Also implies "before flag has been defined".
      global _warn_preinit_stderr
      if _warn_preinit_stderr:
        sys.stderr.write(
            'WARNING: Logging before flag parsing goes to stderr.\n')
        _warn_preinit_stderr = False
      self._log_to_stderr(record)
    elif FLAGS['logtostderr'].value:
      self._log_to_stderr(record)
    else:
      super(PythonHandler, self).emit(record)
      stderr_threshold = converter.string_to_standard(
          FLAGS['stderrthreshold'].value)
      if ((FLAGS['alsologtostderr'].value or level >= stderr_threshold) and
          self.stream != sys.stderr):
        self._log_to_stderr(record)
    # Die when the record is created from ABSLLogger and level is FATAL.
    if _is_absl_fatal_record(record):
      self.flush()  # Flush the log before dying.

      # In threaded python, sys.exit() from a non-main thread only
      # exits the thread in question.
      os.abort() 
Example 43
Project: abseil-py   Author: abseil   File: logging_functional_test.py    Apache License 2.0 5 votes vote down vote up
def _verify_fatal(status, output):
  """Check that helper died as expected."""
  # os.abort generates a SIGABRT signal (-6). On Windows, the process
  # immediately returns an exit code of 3.
  # See https://docs.python.org/3.6/library/os.html#os.abort.
  expected_exit_code = 3 if os.name == 'nt' else -6
  _verify_status(expected_exit_code, status, output) 
Example 44
Project: SDN-QoS-Routing   Author: dodoyuan   File: vsctl.py    Apache License 2.0 5 votes vote down vote up
def not_reached():
    os.abort() 
Example 45
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: shutdown.py    Apache License 2.0 5 votes vote down vote up
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() 
Example 46
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: shutdown_test.py    Apache License 2.0 5 votes vote down vote up
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) 
Example 47
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: shutdown_test.py    Apache License 2.0 5 votes vote down vote up
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() 
Example 48
Project: Project-New-Reign---Nemesis-Main   Author: ShikyoKira   File: test_subprocess.py    GNU General Public License v3.0 5 votes vote down vote up
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) 
Example 49
Project: cells   Author: AlesTsurko   File: test_subprocess.py    MIT License 5 votes vote down vote up
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) 
Example 50
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_catalog.py    GNU General Public License v3.0 4 votes vote down vote up
def test_add_function_ordered(self):
        backup_dir = clear_temp_catalog()
        q = catalog.catalog()

        q.add_function('f',string.upper)
        q.add_function('f',string.lower)
        q.add_function('ff',string.find)
        q.add_function('ff',string.replace)
        q.add_function('fff',string.atof)
        q.add_function('fff',string.atoi)
        del q

        # now we're gonna make a new catalog with same code
        # but different functions in a specified module directory
        env_dir = empty_temp_dir()
        r = catalog.catalog(env_dir)
        r.add_function('ff',os.abort)
        r.add_function('ff',os.chdir)
        r.add_function('fff',os.access)
        r.add_function('fff',os.open)
        del r
        # now we're gonna make a new catalog with same code
        # but different functions in a user specified directory
        user_dir = empty_temp_dir()
        s = catalog.catalog(user_dir)
        s.add_function('fff',re.match)
        s.add_function('fff',re.purge)
        del s

        # open new catalog and make sure it retreives the functions
        # from d catalog instead of the temp catalog (made by q)
        os.environ['PYTHONCOMPILED'] = env_dir
        t = catalog.catalog(user_dir)
        funcs1 = t.get_functions('f')
        funcs2 = t.get_functions('ff')
        funcs3 = t.get_functions('fff')
        restore_temp_catalog(backup_dir)
        # make sure everything is read back in the correct order
        # a little cheating... I'm ignoring any functions that might have
        # been read in from a prior catalog file (such as the defualt one).
        # the test should really be made so that these aren't read in, but
        # until I get this figured out...
        #assert_(funcs1 == [string.lower,string.upper])
        #assert_(funcs2 == [os.chdir,os.abort,string.replace,string.find])
        #assert_(funcs3 == [re.purge,re.match,os.open,
        #                  os.access,string.atoi,string.atof])
        assert_(funcs1[:2] == [string.lower,string.upper]),repr(funcs1)
        assert_(funcs2[:4] == [os.chdir,os.abort,string.replace,string.find])
        assert_(funcs3[:6] == [re.purge,re.match,os.open,
                          os.access,string.atoi,string.atof])
        cleanup_temp_dir(user_dir)
        cleanup_temp_dir(env_dir) 
Example 51
Project: poker   Author: surgebiswas   File: test_catalog.py    MIT License 4 votes vote down vote up
def test_add_function_ordered(self):
        backup_dir = clear_temp_catalog()
        q = catalog.catalog()

        q.add_function('f',string.upper)
        q.add_function('f',string.lower)
        q.add_function('ff',string.find)
        q.add_function('ff',string.replace)
        q.add_function('fff',string.atof)
        q.add_function('fff',string.atoi)
        del q

        # now we're gonna make a new catalog with same code
        # but different functions in a specified module directory
        env_dir = empty_temp_dir()
        r = catalog.catalog(env_dir)
        r.add_function('ff',os.abort)
        r.add_function('ff',os.chdir)
        r.add_function('fff',os.access)
        r.add_function('fff',os.open)
        del r
        # now we're gonna make a new catalog with same code
        # but different functions in a user specified directory
        user_dir = empty_temp_dir()
        s = catalog.catalog(user_dir)
        s.add_function('fff',re.match)
        s.add_function('fff',re.purge)
        del s

        # open new catalog and make sure it retreives the functions
        # from d catalog instead of the temp catalog (made by q)
        os.environ['PYTHONCOMPILED'] = env_dir
        t = catalog.catalog(user_dir)
        funcs1 = t.get_functions('f')
        funcs2 = t.get_functions('ff')
        funcs3 = t.get_functions('fff')
        restore_temp_catalog(backup_dir)
        # make sure everything is read back in the correct order
        # a little cheating... I'm ignoring any functions that might have
        # been read in from a prior catalog file (such as the defualt one).
        # the test should really be made so that these aren't read in, but
        # until I get this figured out...
        #assert_(funcs1 == [string.lower,string.upper])
        #assert_(funcs2 == [os.chdir,os.abort,string.replace,string.find])
        #assert_(funcs3 == [re.purge,re.match,os.open,
        #                  os.access,string.atoi,string.atof])
        assert_(funcs1[:2] == [string.lower,string.upper]),repr(funcs1)
        assert_(funcs2[:4] == [os.chdir,os.abort,string.replace,string.find])
        assert_(funcs3[:6] == [re.purge,re.match,os.open,
                          os.access,string.atoi,string.atof])
        cleanup_temp_dir(user_dir)
        cleanup_temp_dir(env_dir) 
Example 52
Project: claripy   Author: angr   File: backend_z3_parallel.py    BSD 2-Clause "Simplified" License 4 votes vote down vote up
def _background(self, f_name, *args, **kwargs):
        global num_children

        f = getattr(BackendZ3, f_name)
        if self._child:
            return f(self, *args, **kwargs)

        p_r, p_w = os.pipe()
        p = os.fork()

        if p == 0:
            self._child = True
            self._lock = threading.RLock()
            try:
                r = f(self, *args, **kwargs)
            except UnsatError as e:
                r = e

            # print("WRITING (%d)" % os.getpid())
            pickled = pickle.dumps(r, -1)
            written = 0
            while written < len(pickled):
                written += os.write(p_w, pickled[written:])
            os.close(p_w)
            os.close(p_r)
            # print("WROTE (%d)" % os.getpid())

            os.kill(os.getpid(), 9)
            #os.abort()
            #sys.exit(1)
        else:
            os.close(p_w)

            num_children += 1
            l.debug("in _background with function %s and child %d (among %d)", f, p, num_children)

            # print("READING (from %d)" % p)
            try:
                strs = [ os.read(p_r, 1024*1024) ]
                while strs[-1] != "": strs.append(os.read(p_r, 1024*1024))
            except EOFError:
                raise ClaripyError("read error while receiving data from child")
            os.close(p_r)
            # print("READ (from %d)" % p)

            # thread.start_new_thread(os.wait, ())
            r = pickle.loads("".join(strs))

            os.waitpid(p, 0)
            num_children -= 1
            l.debug("... child %d is done. %d left", p, num_children)

            if isinstance(r, Exception): raise r
            else: return r 
Example 53
Project: virtualchain   Author: blockstack   File: indexer.py    GNU General Public License v3.0 4 votes vote down vote up
def make_backups(self, block_id):
        """
        If we're doing backups on a regular basis, then 
        carry them out here if it is time to do so.
        This method does nothing otherwise.

        Return None on success
        Abort on failure
        """
        assert self.setup, "Not set up yet.  Call .db_setup() first!"

        # make a backup?
        if self.backup_frequency is not None:
            if (block_id % self.backup_frequency) == 0:

                backup_dir = config.get_backups_directory(self.impl, self.working_dir)
                if not os.path.exists(backup_dir):
                    try:
                        os.makedirs(backup_dir)
                    except Exception, e:
                        log.exception(e)
                        log.error("FATAL: failed to make backup directory '%s'" % backup_dir)
                        traceback.print_stack()
                        os.abort()

                for p in self.get_state_paths(self.impl, self.working_dir):
                    if os.path.exists(p):
                        try:
                            pbase = os.path.basename(p)
                            backup_path = os.path.join(backup_dir, pbase + (".bak.{}".format(block_id - 1)))

                            if not os.path.exists(backup_path):
                                rc = sqlite3_backup(p, backup_path)
                                if not rc:
                                    log.warning("Failed to back up as an SQLite db.  Falling back to /bin/cp")
                                    shutil.copy(p, backup_path)
                            else:
                                log.error("Will not overwrite '%s'" % backup_path)

                        except Exception, e:
                            log.exception(e)
                            log.error("FATAL: failed to back up '%s'" % p)
                            traceback.print_stack()
                            os.abort() 
Example 54
Project: virtualchain   Author: blockstack   File: indexer.py    GNU General Public License v3.0 4 votes vote down vote up
def snapshot(self, block_id, oplist):
        """
        Given the currnet block ID and the set of operations committed,
        find the consensus hash that represents the state of the virtual chain.
        
        The consensus hash is calculated as a Merkle skip-list.  It incorporates:
        * block K's operations 
        * block K - 1's consensus hash 
        * block K - 2 - 1's consensus hash 
        * block K - 4 - 2 - 1's consensus hash, 
        ...
        * block K - (2**i - 1)'s consensus hash
        
        The purpose of this construction is that it reduces the number of queries 
        a client needs to verify the integrity of previously-processed operations
        to a *sublinear* function of the length of the virtual blockchain.
        
        For example, if there are 15 blocks in the virtual chain, and a client has 
        the consensus hash for block 15 (ch[15]) but wants to verify an operation at block 3, the 
        client would:
        1.    Fetch ops[15], ch[14], ch[12], ch[8], ch[0]
        2.    Verify (1) with ch[15], so ch[8] is trusted.
        3.    Fetch ops[8], ch[7], ch[5], ch[1]
        4.    Verify (3) with ch[8], so ch[5] is trusted
        5.    Fetch ops[5], ch[3]
        6.    Verify (5) and ch[1] from (3) with ch[5], so ch[3] is trusted
        7.    Fetch ops[3], ch[2]
        8.    Verify (7) and ch[0] from (1) with ch[3], so ops[3] is trusted
        9.    Verify op in ops[3]

        Returns (consensus hash, ops_hash)
        """
        
        assert self.setup, "Not set up yet.  Call .db_setup() first!"
        log.debug("Snapshotting block {}".format(block_id))
        
        serialized_ops = []
        for opdata in oplist:
            serialized_record = StateEngine.serialize_op(opdata['virtualchain_opcode'], opdata, self.opfields)
            serialized_ops.append( serialized_record )

        previous_consensus_hashes = []
        k = block_id
        i = 1
        while k - (2**i - 1) >= self.impl.get_first_block_id():
            prev_block = k - (2**i - 1)
            prev_ch = self.get_consensus_at(prev_block)
            log.debug("Snapshotting block %s: consensus hash of %s is %s" % (block_id, prev_block, prev_ch))

            if prev_ch is None:
                log.error("BUG: None consensus for %s" % prev_block )
                traceback.print_stack()
                os.abort()

            previous_consensus_hashes.append(prev_ch)
            i += 1

        consensus_hash, ops_hash = StateEngine.make_snapshot(serialized_ops, previous_consensus_hashes) 
        return consensus_hash, ops_hash 
Example 55
Project: virtualchain   Author: blockstack   File: indexer.py    GNU General Public License v3.0 4 votes vote down vote up
def process_block(self, block_id, ops, backup=False, expected_snapshots=None):
        """
        Top-level block processing method.
        Feed the block and its data transactions 
        through the implementation, to build up the 
        implementation's state.  Cache the 
        resulting data to disk.
       
        Return the (consensus hash, ops hash) for this block on success.
        Exit on failure.
        """
        
        log.debug("Process block {} ({} virtual transactions)".format(block_id, len(ops)))

        if expected_snapshots is None:
            expected_snapshots = self.expected_snapshots
        if expected_snapshots is None:
            expected_snapshots = {}
        
        new_ops = self.process_ops(block_id, ops)
        consensus_hash, ops_hash = self.snapshot(block_id, new_ops['virtualchain_ordered'])

        # sanity check against a known sequence of consensus hashes
        if block_id in expected_snapshots:
            log.debug("Expecting CONSENSUS({}) == {}".format(block_id, expected_snapshots[block_id]))
            if expected_snapshots[block_id] != consensus_hash:
                log.error("FATAL: consensus hash mismatch at height {}: {} != {}".format(block_id, expected_snapshots[block_id], consensus_hash))
                traceback.print_stack()
                os.abort()
        
        # remove virtualchain-reserved keys
        sanitized_ops = []
        virtualchain_ops_hints = []
        for opdata in new_ops['virtualchain_ordered']:
            op_sanitized, op_reserved = self.remove_reserved_keys(opdata)
            sanitized_ops.append(op_sanitized)
            virtualchain_ops_hints.append(op_reserved)

        # save state for this block
        rc = self.save(block_id, consensus_hash, ops_hash, sanitized_ops, virtualchain_ops_hints, backup=backup)
        if not rc:
            # implementation requests early termination 
            log.debug("Early indexing termination at {}".format(block_id))
            return None

        # store statistics if we're in test mode 
        if os.environ.get("BLOCKSTACK_TEST"):
            global STATISTICS
            STATISTICS[block_id] = {
                'consensus_hash': consensus_hash,
                'num_parsed_ops': len(ops),
                'num_processed_ops': len(new_ops['virtualchain_ordered']),
                'ops_hash': ops_hash,
                'backup': backup,
            }

        return consensus_hash