python gc模块_Python gc.threshold方法代码示例

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

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

示例1: run_gc

​点赞 6

# 需要导入模块: 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,

示例2: from_pyboard

​点赞 5

# 需要导入模块: 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,

示例3: mem_manage

​点赞 5

# 需要导入模块: 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,

示例4: _garbage_collect

​点赞 5

# 需要导入模块: 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,

示例5: _make_json_response

​点赞 5

# 需要导入模块: 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,

示例6: _make_html_response

​点赞 5

# 需要导入模块: 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,

示例7: monkeypatch_stdlib

​点赞 5

# 需要导入模块: 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,

示例8: monkeypatch_stdlib

​点赞 4

# 需要导入模块: 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,

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值