本文整理匯總了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())
示例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.
示例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())
示例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
示例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')
示例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')
示例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()
示例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()