本文整理匯總了Python中gc.mem_alloc方法的典型用法代碼示例。如果您正苦於以下問題:Python gc.mem_alloc方法的具體用法?Python gc.mem_alloc怎麽用?Python gc.mem_alloc使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類gc
的用法示例。
在下文中一共展示了gc.mem_alloc方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run_gc
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_alloc [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: collect_garbage
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_alloc [as 別名]
def collect_garbage(self):
gc.collect()
if config_lora.IS_MICROPYTHON:
print('[Memory - free: {} allocated: {}]'.format(gc.mem_free(), gc.mem_alloc()))
示例3: _memory
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_alloc [as 別名]
def _memory(self):
count = 0
while self.isconnected(): # Ensure just one instance.
await asyncio.sleep(1) # Quick response to outage.
count += 1
count %= 20
if not count:
gc.collect()
print('RAM free {} alloc {}'.format(gc.mem_free(), gc.mem_alloc()))
示例4: from_pyboard
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_alloc [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.
示例5: get
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_alloc [as 別名]
def get(self, data):
mem = {'mem_alloc': gc.mem_alloc(),
'mem_free': gc.mem_free(),
'mem_total': gc.mem_alloc() + gc.mem_free()}
sta_if = network.WLAN(network.STA_IF)
ifconfig = sta_if.ifconfig()
net = {'ip': ifconfig[0],
'netmask': ifconfig[1],
'gateway': ifconfig[2],
'dns': ifconfig[3]
}
return {'memory': mem, 'network': net}
# RESTAPI: GPIO status
示例6: _print_debug_cycle
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_alloc [as 別名]
def _print_debug_cycle(self, init=False):
pre_alloc = gc.mem_alloc()
pre_free = gc.mem_free()
if self.debug_enabled:
if init:
print('KMKInit(release={})'.format(KMK_RELEASE))
print(self)
print(self._state)
print(
'GCStats(pre_alloc={} pre_free={} alloc={} free={})'.format(
pre_alloc, pre_free, gc.mem_alloc(), gc.mem_free()
)
)
示例7: mem_manage
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_alloc [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())
示例8: get_gc_stats
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_alloc [as 別名]
def get_gc_stats(self):
import gc
return {
'mem_alloc': gc.mem_alloc(),
'mem_free': gc.mem_free()
}
示例9: handle_command
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_alloc [as 別名]
def handle_command(self, args):
import gc
mem_alloc = gc.mem_alloc()
mem_free = gc.mem_free()
capacity = mem_alloc + mem_free
print(" capacity\tfree\tusage")
print(" {}\t{}\t{}%".format(capacity, mem_free, int(
((capacity - mem_free) / capacity) * 100.0)))
if "-i" in args:
import micropython
micropython.mem_info(1)
示例10: get_memory_stats
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_alloc [as 別名]
def get_memory_stats(self):
mem_alloc = gc.mem_alloc()
mem_free = gc.mem_free()
return {
'mem_alloc': mem_alloc,
'mem_free': mem_free
}
示例11: mem
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_alloc [as 別名]
def mem(level=None):
import gc
mem_alloc = gc.mem_alloc()
mem_free = gc.mem_free()
capacity = mem_alloc + mem_free
print(" capacity\tfree\tusage")
print(" {}\t{}\t{}%".format(capacity, mem_free, int(
((capacity - mem_free) / capacity) * 100.0)))
if level:
import micropython
micropython.mem_info(level)
示例12: __init__
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_alloc [as 別名]
def __init__(self, sleep_ms=5*1000, verbose=False) :
TaskBase.__init__(self, sleep_ms)
self.verbose = verbose
self.mem_free = 0
self.mem_alloc = 0
self.min_collected = 2**32
self.max_collected = 0
self.sum_collected = 0
self.num_collections = 0
示例13: perform
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_alloc [as 別名]
def perform(self) :
import gc
mem_free_before = gc.mem_free()
gc.collect()
self.mem_free = gc.mem_free()
self.mem_alloc = gc.mem_alloc()
mem_collected = self.mem_free - mem_free_before
if mem_collected < self.min_collected :
self.min_collected = mem_collected
if self.max_collected < mem_collected :
self.max_collected = mem_collected
self.sum_collected += mem_collected
self.num_collections += 1
return True
示例14: _garbage_collect
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_alloc [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
示例15: collect_garbage
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_alloc [as 別名]
def collect_garbage(self):
gc.collect()
if __DEBUG__:
print('[Memory - free: {} allocated: {}]'.format(gc.mem_free(), gc.mem_alloc()))