Skip to content

Threading

Alex Schendel edited this page Jun 27, 2019 · 1 revision

This wiki discusses using multi-threading to run multiple robot commands simultaneously.

Why use multi-threading?

Basically, a thread is one path of execution for your program. Normally, an application gets one thread and just keeps running on that. This one thread does everything for the application sequentially. Normally, that's okay because the computer can do stuff real quick, but what if you have a particularly long-running function? Then all of a sudden your entire app is stuck finishing the execution of that one function and can't do anything else while it's running that.

This is bad design, especially if you are interacting with users because the UI will become unresponsive and the user will think your application has crashed. In any case, that doesn't apply to our robot, but it would still prevent us from running multiple commands at the same time. The way we get around having one command stop our robot from responding to anything else is to have our program multi-threaded. This means each command will run on its own separate thread, allowing for all of them to be processed simultaneously (technically they aren't EXACTLY simultaneous, but it is certainly good enough for our purposes).

The idea is that we use one of Python's multi-threading libraries (multiprocessing, threading, asyncio, etc.) to run multiple commands at the same time and keep them synchronized. This way we are free to stop the robot whenever we need to and get to run as many commands at the same time as we please. (Update this when this is actually being developed)

Clone this wiki locally