harmsm / PyCmdMessenger

Python interface for CmdMessenger arduino serial communication library
MIT License
80 stars 32 forks source link

Non-blocking Listener #30

Closed nick5435 closed 5 years ago

nick5435 commented 7 years ago

Could be a good idea to implement CmdMessenger.receive as an asynchronous task, that way tasks don't get blocked listening for a response. PySerial has started a Pyserial-Asyncio client.

rytrose commented 5 years ago

@nick5435 I just did a bunch of research to see what the damage would be to implement this via pyserial-asyncio. It's a pretty substantial amount of work. I don't know what your use-case is (if you still have on > 1 year later), but if you're not communicating lots and lots of data, you're probably just better off making a thread like so:

while True: 
    msg = c.receive()
    # do stuff with msg, probably on another thread
nick5435 commented 5 years ago

I haven't worked on the project that used this for over a year. I believe we ended up doing something similar with multithreading.