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


Python gc.threshold方法代码示例

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


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

示例1: run_gc

# 需要导入模块: import gc [as 别名]
# 或者: from gc import threshold [as 别名]
def run_gc(self):
        """
        Curate the garbage collector.
        https://docs.pycom.io/firmwareapi/micropython/gc.html

        For a "quick fix", issue the following periodically.
        https://community.hiveeyes.org/t/timing-things-on-micropython-for-esp32/2329/9

        """
        import gc
        log.info('Start curating the garbage collector')
        gc.threshold(gc.mem_free() // 4 + gc.mem_alloc())
        log.info('Collecting garbage')
        gc.collect()
        #log.info('Curating the garbage collector finished')
        log.info('Curating the garbage collector finished. Free memory: %s', gc.mem_free()) 
开发者ID:hiveeyes,项目名称:terkin-datalogger,代码行数:18,代码来源:device.py

示例2: from_pyboard

# 需要导入模块: import gc [as 别名]
# 或者: from gc import threshold [as 别名]
def from_pyboard(self):
        client = self.client
        while True:
            istr = await self.await_obj(20)  # wait for string (poll interval 20ms)
            s = istr.split(SEP)
            command = s[0]
            if command == PUBLISH:
                await client.publish(s[1], s[2], bool(s[3]), int(s[4]))
                # If qos == 1 only returns once PUBACK received.
                self.send(argformat(STATUS, PUBOK))
            elif command == SUBSCRIBE:
                await client.subscribe(s[1], int(s[2]))
                client.subscriptions[s[1]] = int(s[2])  # re-subscribe after outage
            elif command == MEM:
                gc.collect()
                gc.threshold(gc.mem_free() // 4 + gc.mem_alloc())
                self.send(argformat(MEM, gc.mem_free(), gc.mem_alloc()))
            elif command == TIME:
                t = await client.get_time()
                self.send(argformat(TIME, t))
            else:
                self.send(argformat(STATUS, UNKNOWN, 'Unknown command:', istr))

# Runs when channel has synchronised. No return: Pyboard resets ESP on fail.
# Get parameters from Pyboard. Process them. Connect. Instantiate client. Start
# from_pyboard() task. Wait forever, updating connected status. 
开发者ID:peterhinch,项目名称:micropython-mqtt,代码行数:28,代码来源:mqtt.py

示例3: mem_manage

# 需要导入模块: import gc [as 别名]
# 或者: from gc import threshold [as 别名]
def mem_manage():         # Necessary for long term stability
    while True:
        await asyncio.sleep_ms(100)
        gc.collect()
        gc.threshold(gc.mem_free() // 4 + gc.mem_alloc()) 
开发者ID:micropython-IMU,项目名称:micropython-fusion,代码行数:7,代码来源:fusionlcd.py

示例4: _garbage_collect

# 需要导入模块: import gc [as 别名]
# 或者: from gc import threshold [as 别名]
def _garbage_collect(self):
        while True:
            await asyncio.sleep_ms(100)
            gc.collect()
            gc.threshold(gc.mem_free() // 4 + gc.mem_alloc())

# Very basic window class. Cuts a rectangular hole in a screen on which content may be drawn 
开发者ID:peterhinch,项目名称:micropython-tft-gui,代码行数:9,代码来源:ugui.py

示例5: _make_json_response

# 需要导入模块: import gc [as 别名]
# 或者: from gc import threshold [as 别名]
def _make_json_response(self, results, healthy):
        if self._show_details:
            body = {
                'detailed': True,
                'python_version': sys.version,
                'now': str(timeutils.utcnow()),
                'platform': platform.platform(),
                'gc': {
                    'counts': gc.get_count(),
                    'threshold': gc.get_threshold(),
                },
            }
            reasons = []
            for result in results:
                reasons.append({
                    'reason': result.reason,
                    'details': result.details or '',
                    'class': reflection.get_class_name(result,
                                                       fully_qualified=False),
                })
            body['reasons'] = reasons
            body['greenthreads'] = self._get_greenstacks()
            body['threads'] = self._get_threadstacks()
        else:
            body = {
                'reasons': [result.reason for result in results],
                'detailed': False,
            }
        return (self._pretty_json_dumps(body), 'application/json') 
开发者ID:openstack,项目名称:oslo.middleware,代码行数:31,代码来源:__init__.py

示例6: _make_html_response

# 需要导入模块: import gc [as 别名]
# 或者: from gc import threshold [as 别名]
def _make_html_response(self, results, healthy):
        try:
            hostname = socket.gethostname()
        except socket.error:
            hostname = None
        translated_results = []
        for result in results:
            translated_results.append({
                'details': result.details or '',
                'reason': result.reason,
                'class': reflection.get_class_name(result,
                                                   fully_qualified=False),
            })
        params = {
            'healthy': healthy,
            'hostname': hostname,
            'results': translated_results,
            'detailed': self._show_details,
            'now': str(timeutils.utcnow()),
            'python_version': sys.version,
            'platform': platform.platform(),
            'gc': {
                'counts': gc.get_count(),
                'threshold': gc.get_threshold(),
             },
             'threads': self._get_threadstacks(),
             'greenthreads': self._get_threadstacks(),
        }
        body = _expand_template(self.HTML_RESPONSE_TEMPLATE, params)
        return (body.strip(), 'text/html') 
开发者ID:openstack,项目名称:oslo.middleware,代码行数:32,代码来源:__init__.py

示例7: monkeypatch_stdlib

# 需要导入模块: import gc [as 别名]
# 或者: from gc import threshold [as 别名]
def monkeypatch_stdlib():

    import builtins
    builtins.const = int

    sys.modules['micropython'] = Mock()
    sys.modules['micropython'].const = int

    import struct
    sys.modules['ustruct'] = struct

    import binascii
    sys.modules['ubinascii'] = binascii

    import time
    def ticks_ms():
        import time
        return time.time() * 1000
    def ticks_diff(ticks1, ticks2):
        return abs(ticks1 - ticks2)
    time.ticks_ms = ticks_ms
    time.ticks_diff = ticks_diff
    sys.modules['utime'] = time

    import io
    sys.modules['uio'] = io

    import os
    sys.modules['uos'] = os

    import gc
    gc.threshold = Mock()
    gc.mem_free = Mock(return_value=1000000)
    gc.mem_alloc = Mock(return_value=2000000)

    # Optional convenience to improve speed.
    gc.collect = Mock() 
开发者ID:hiveeyes,项目名称:terkin-datalogger,代码行数:39,代码来源:micropython.py

示例8: monkeypatch_stdlib

# 需要导入模块: import gc [as 别名]
# 或者: from gc import threshold [as 别名]
def monkeypatch_stdlib():

    from mock import Mock

    import time
    sys.modules['utime'] = time

    import builtins
    builtins.const = int

    import struct
    sys.modules['ustruct'] = struct

    import binascii
    sys.modules['ubinascii'] = binascii

    import time
    def ticks_ms():
        import time
        return time.time() * 1000
    def ticks_diff(ticks1, ticks2):
        return abs(ticks1 - ticks2)
    time.ticks_ms = ticks_ms
    time.ticks_diff = ticks_diff
    sys.modules['utime'] = time

    import io
    sys.modules['uio'] = io

    import os
    sys.modules['uos'] = os

    sys.modules['micropython'] = Mock()
    sys.modules['micropython'].const = int

    import gc
    gc.threshold = Mock()
    gc.mem_free = Mock(return_value=1000000)
    gc.mem_alloc = Mock(return_value=2000000)

    # Optional convenience to improve speed.
    gc.collect = Mock() 
开发者ID:hiveeyes,项目名称:terkin-datalogger,代码行数:44,代码来源:compat.py


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