本文整理匯總了Python中gc.mem_free方法的典型用法代碼示例。如果您正苦於以下問題:Python gc.mem_free方法的具體用法?Python gc.mem_free怎麽用?Python gc.mem_free使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類gc
的用法示例。
在下文中一共展示了gc.mem_free方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_free [as 別名]
def main(client):
try:
await client.connect()
except OSError:
print('Connection failed.')
return
n = 0
s = '{} repubs: {} outages: {} rssi: {}dB free: {}bytes'
while True:
await asyncio.sleep(5)
gc.collect()
m = gc.mem_free()
print('publish', n)
# If WiFi is down the following will pause for the duration.
await client.publish(TOPIC, s.format(n, client.REPUB_COUNT, outages, rssi, m), qos = 1)
n += 1
# Define configuration
示例2: main
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_free [as 別名]
def main():
try:
print("initializing camera")
#cam = ov2640.ov2640(resolution=ov2640.OV2640_320x240_JPEG)
cam = ov2640.ov2640(resolution=ov2640.OV2640_1024x768_JPEG)
print(gc.mem_free())
clen = cam.capture_to_file(FNAME, True)
print("captured image is %d bytes" % clen)
print("image is saved to %s" % FNAME)
time.sleep(10)
sys.exit(0)
except KeyboardInterrupt:
print("exiting...")
sys.exit(0)
示例3: _receiveConfig
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_free [as 別名]
def _receiveConfig():
await asyncio.sleep(2)
_log.debug("RAM before import receiveConfig:", gc.mem_free(), local_only=True)
import pysmartnode.components.machine.remoteConfig
gc.collect()
_log.debug("RAM after import receiveConfig:", gc.mem_free(), local_only=True)
conf = pysmartnode.components.machine.remoteConfig.RemoteConfig()
gc.collect()
_log.debug("RAM after creating receiveConfig:", gc.mem_free(), local_only=True)
while not conf.done():
await asyncio.sleep(1)
gc.collect()
_log.debug("RAM before deleting receiveConfig:", gc.mem_free(), local_only=True)
await conf.removeComponent(conf) # removes component from Component chain
del conf
del pysmartnode.components.machine.remoteConfig
del sys.modules["pysmartnode.components.machine.remoteConfig"]
gc.collect()
_log.debug("RAM after deleting receiveConfig:", gc.mem_free(), local_only=True)
示例4: get_onboard_button_events
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_free [as 別名]
def get_onboard_button_events(self, btn, bcc_key, on_single_click, on_double_click):
import gc
from machine import Timer
if btn.value() == 0:
self.button_click_counter[bcc_key] += 1
if self.button_click_counter[bcc_key] == 1:
log.info("single-click registered (mem free: " + str(gc.mem_free()) + ")")
sc = getattr(tk, on_single_click)
sc()
elif self.button_click_counter[bcc_key] == 2:
log.info("double click registered (mem free: " + str(gc.mem_free()) + ")")
sc = getattr(tk, on_double_click)
sc()
else:
pass
gtim = Timer(1)
gtim.init(period=300, mode=Timer.ONE_SHOT, callback=lambda t:self.reset_onboard_button_event_counter(bcc_key))
# @timed_function
示例5: run_gc
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_free [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())
示例6: _memory
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_free [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()))
示例7: collect_garbage
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_free [as 別名]
def collect_garbage(self):
gc.collect()
if config_lora.IS_MICROPYTHON:
print('[Memory - free: {} allocated: {}]'.format(gc.mem_free(), gc.mem_alloc()))
示例8: from_pyboard
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_free [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.
示例9: get
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_free [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
示例10: report
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_free [as 別名]
def report(self, time):
data = [0, 0, 0]
count = 0
while True:
await asyncio.sleep(time)
data[0] = self.cl.connects # For diagnostics
data[1] = count
count += 1
gc.collect()
data[2] = gc.mem_free()
line = 'r{}\n'.format(ujson.dumps(data))
self.swriter.write(line)
await self.swriter.drain()
示例11: writer
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_free [as 別名]
def writer(self):
self.verbose and print('Started writer')
data = [0, 0, 0]
count = 0
while True:
data[0] = self.cl.connects
data[1] = count
count += 1
gc.collect()
data[2] = gc.mem_free()
print('Sent', data, 'to server app\n')
# .write() behaves as per .readline()
await self.cl.write(ujson.dumps(data))
await asyncio.sleep(5)
示例12: writer
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_free [as 別名]
def writer(self):
self.verbose and print('Started writer')
while True:
for _ in range(4):
gc.collect()
data = [self.tx_msg_id, self.cl.connects, gc.mem_free(),
self.cm.dupe, self.cm.miss]
self.tx_msg_id += 1
await self.cl # Only launch write if link is up
print('Sent', data, 'to server app\n')
dstr = ujson.dumps(data)
asyncio.create_task(self.cl.write(dstr, wait=False))
await asyncio.sleep(5)
示例13: writer
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_free [as 別名]
def writer(self):
self.verbose and print('Started writer')
while True:
gc.collect()
data = [self.tx_msg_id, self.cl.connects, gc.mem_free(),
self.cm.dupe, self.cm.miss]
self.tx_msg_id += 1
print('Sent', data, 'to server app\n')
dstr = ujson.dumps(data)
await self.cl.write(dstr) # Wait out any outage
await asyncio.sleep_ms(7000 + urandom.getrandbits(10))
示例14: _print_debug_cycle
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_free [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()
)
)
示例15: dosettings
# 需要導入模塊: import gc [as 別名]
# 或者: from gc import mem_free [as 別名]
def dosettings():
switch_to(settings)
settings.set_memfree(str(gc.mem_free()))