Python gc.mem_alloc() Examples
The following are 22
code examples of gc.mem_alloc().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
gc
, or try the search function
.
Example #1
Source File: device.py From terkin-datalogger with GNU Affero General Public License v3.0 | 6 votes |
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())
Example #2
Source File: cmd.py From esp8266 with BSD 2-Clause "Simplified" License | 6 votes |
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)
Example #3
Source File: ush.py From esp8266 with BSD 2-Clause "Simplified" License | 5 votes |
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)
Example #4
Source File: micropython.py From terkin-datalogger with GNU Affero General Public License v3.0 | 5 votes |
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()
Example #5
Source File: mqtt_as.py From microhomie with MIT License | 5 votes |
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()))
Example #6
Source File: sx127x.py From uPyLoRaWAN with Apache License 2.0 | 5 votes |
def collect_garbage(self): gc.collect() if __DEBUG__: print('[Memory - free: {} allocated: {}]'.format(gc.mem_free(), gc.mem_alloc()))
Example #7
Source File: ugui.py From micropython-tft-gui with MIT License | 5 votes |
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
Example #8
Source File: task.py From esp8266 with BSD 2-Clause "Simplified" License | 5 votes |
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
Example #9
Source File: task.py From esp8266 with BSD 2-Clause "Simplified" License | 5 votes |
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
Example #10
Source File: api.py From esp8266 with BSD 2-Clause "Simplified" License | 5 votes |
def get_memory_stats(self): mem_alloc = gc.mem_alloc() mem_free = gc.mem_free() return { 'mem_alloc': mem_alloc, 'mem_free': mem_free }
Example #11
Source File: sx127x.py From SX127x_driver_for_MicroPython_on_ESP8266 with GNU General Public License v3.0 | 5 votes |
def collect_garbage(self): gc.collect() if config_lora.IS_MICROPYTHON: print('[Memory - free: {} allocated: {}]'.format(gc.mem_free(), gc.mem_alloc()))
Example #12
Source File: stats_api.py From esp8266 with BSD 2-Clause "Simplified" License | 5 votes |
def get_gc_stats(self): import gc return { 'mem_alloc': gc.mem_alloc(), 'mem_free': gc.mem_free() }
Example #13
Source File: capture.py From micropython-fusion with MIT License | 5 votes |
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())
Example #14
Source File: fusiontest_as.py From micropython-fusion with MIT License | 5 votes |
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())
Example #15
Source File: fusiontest_as6.py From micropython-fusion with MIT License | 5 votes |
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())
Example #16
Source File: fusionlcd.py From micropython-fusion with MIT License | 5 votes |
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())
Example #17
Source File: kmk_keyboard.py From kmk_firmware with GNU General Public License v3.0 | 5 votes |
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() ) )
Example #18
Source File: esp8266.py From tinyweb with MIT License | 5 votes |
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
Example #19
Source File: mqtt.py From micropython-mqtt with MIT License | 5 votes |
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.
Example #20
Source File: mqtt_as.py From micropython-mqtt with MIT License | 5 votes |
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()))
Example #21
Source File: sx127x.py From SX127x_driver_for_MicroPython_on_ESP8266 with GNU General Public License v3.0 | 5 votes |
def collect_garbage(self): gc.collect() if config_lora.IS_MICROPYTHON: print('[Memory - free: {} allocated: {}]'.format(gc.mem_free(), gc.mem_alloc()))
Example #22
Source File: compat.py From terkin-datalogger with GNU Affero General Public License v3.0 | 4 votes |
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()