arduino / arduino-lib-mpy

Packages to be included in Arduino MicroPython distros as frozen modules
Mozilla Public License 2.0
1 stars 1 forks source link

rpc.call_async() without Future #12

Open razvanphp opened 6 days ago

razvanphp commented 6 days ago

I am writing a dual-core app running on Portenta H7 with micropython on M7 + arduino code on M4.

My use-case for true paralelism is to call a function and never expect for the return value (since it's void anyway). I want to do this call in a non-blocking way, so I used rpc.call_async() but after 150 calls, I get this error:

timeout waiting for a free buffer
(OR)
memory allocation failed, allocating 4168 bytes

This does not happen with rpc.call(), but I do not want to introduce latency.

How can we achieve this?

Thanks! R

iabdalkader commented 5 days ago

return value (since it's void anyway).

It's a request-response protocol; all requests return responses, even if the called function returns void, as defined by the protocol here: https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md#response-message

but after 150 calls, I get this error:

If you don't join future objects you will run out of memory eventually. All future objects must be joined at some point so they're collected and free'd. Async calls are also described in the protocol: https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md#step-2-asynchronous-call

The library implements the protocol specs as closely as possible. If you want a different behavior you could try changing the code to discard async-responses, if they're not needed, but I don't think we want this as a feature.

razvanphp commented 20 hours ago

my intention is not to break the protocol specs, but to have a way to support this case as well, avoiding the memory fillup.

Any suggestion how can I clean up the Future objects, maybe doing self.msgbuf.pop() automatically as soon as a response is received? I think it would be useful for more people than us, it's not so uncommon to have a void function call.

Alternative to wait for the answer makes no sense for dual-cpu usage, as it will block the current thread during this time.

Thanks! R