micropython / micropython/micropython-lib
aioble: Unhandled exception in IRC callback - memory allocation failed
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.9k
- Forks
- 1.1k
- Avg merge
- 7d 6h
- Merged PRs (30d)
- 3
Description
Hi,
I have a function that scans for advertising data and decode the information (Ruuvi temperature sensors). However, when this runs for a while together with some other tasks, I'm running into a memory issue.
Unhandled exception in IRQ callback handler
Traceback (most recent call last):
File "core.py", line 71, in ble_irq
File "central.py", line 61, in _central_irq
MemoryError: memory allocation failed, allocating 2048 bytes
This will quit my background BLE scanning task which is updating my temperature data. Of course I can watch the task and restart it, but I hope for a better error handling the the aioble library.
It runs fine for quite some time before it giving the error. It's not reproducible - sometimes it occurs after 5 minutes, sometimes it runs 2h without any issues.
I tried running an exception catcher around the can itself:
try:
async with aioble.scan(duration_ms = duration, interval_us=30000, window_us=30000, active = True) as scanner:
self.scanner = scanner
async for result in scanner:
self._handle_advertisement(result)
except Exception as e:
print('!!!!! Exception in aioble scan')
print(e)
But this doesn't help to prevent the error from happing. Of course I could change the code in central.py myself and see if I can catch the error, but I don't want to mess around with it (yet).
I already have another task that is frequently running a gc.collect() and memory shows up with round 32kB.
Thanks....
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with core.py line 71 and central.py line 61, the IRQ callback path shown in the traceback. Run the long-lived aioble.scan workload with the other tasks and observe how MemoryError affects the scanning task. Done means the desired behavior for allocation failure is defined and verified without silently stopping the background scan.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100