JamesDevJim / game-zulu

First game of the coolest project
0 stars 1 forks source link

Use of busy-wait loops #4

Open shuttle1987 opened 4 years ago

shuttle1987 commented 4 years ago

https://github.com/JamesDevJim/game-zulu/blob/4b46243499803992d0ef07bb856fb49bb8f72240/test_light_strip.py#L14-L17

You'll notice if you have multiple embedded devices that you wish to control that this pattern of programming will start to cause problems. This particular pattern is known as a "busy wait loop" it will keep the python process completely locked up trying to service the input from that one Arduino device. Depending on your requirements there are various options to deal with this but most approaches will involve some form of concurrency that lets your game keep chugging along while it's servicing the input from various devices (Threading vs asyncio vs other approaches).

You may find a queue useful for these situations whereby commands for incoming devices are placed onto the queue and some central processing occurs to clear these events out of the queue.

shuttle1987 commented 4 years ago

https://en.wikipedia.org/wiki/Busy_waiting for reference

JamesDevJim commented 4 years ago

This would be very helpful!