Threads in Python (VEXCode)

Here is an example of how you can use threading with python in VEXcode:

# ------------------------------------------
# 
# 	Project:      VR_THREAD EXAMPLE
#	Author:       MARK JOHNSTON
#	Created:      2021-07-28
#	Description:  
# 
# ------------------------------------------

# Library imports
from vexcode import *

# This is the main thread
def main():
    while True:
        drivetrain.drive_for(FORWARD, 200, MM)
        drivetrain.turn_for(RIGHT, 90, DEGREES)

# This is a seondary thread that will run in parallel
def monitoring():
    while True:
        brain.clear()
        brain.print(brain.timer_time(SECONDS), precision=-1)
        wait(5,MSEC)

# VR threads
vr_thread(main())
vr_thread(monitoring())

In the example above, I used the timer to illustrate that you can use threads to have multiple things going on at once (instead of being interrupted by program flow).

Let me know if you have any questions or comments!