Event vs. Thread

Hello all,

In perusing through the UR and Polyscope manuals, I am having a hard time telling the difference between the efficiency and use of the “Thread” command, and the “Event” command. Is “Thread” used to contain a number of various commands as a way of organization, whilst “Event” is reserved for simpler tasks?

Any help would be appreciated, thanks

“Threads” in programming are parallel tasks. They run AT THE SAME TIME as your main program. This can be useful for monitoring inputs or other sensor values. Think of this as another Main Program.

Events are exactly the same thing as a thread, it’s just that Polyscope does a little more house keeping for you. In effect, it will run the code contained in the event ONCE per desired input condition. In fact, the script code Polyscope generates is just a thread:


In short, an event does nothing that a thread cannot do, it just does a little bit of additional prep work for you if you want code to run ONCE as opposed to continuously

1 Like

It is a little misleading saying it will run ONCE, isn’t it? :slight_smile: It’s a while-command and will act entirely as a thread and loop itself continuously as long as the input is true.

If you want to only run the event once, the event input must be set false before the execution of the last command (or as the last command) of the event.


Oops, yep you’re 100% correct!

The other thing to be careful about with events is that IF you have multiple events configured and event A is configured to execute first (within polyscope) and event B is second, IF and while event A is active only it will execute (out of all the events) and event B will not execute. If event B is active (while event A is not) and then event A becomes active the code under event A will execute and event B will not.

I agree this is not exactly intuitive but it is the way it works.

Now a straight thread(s) that is/are configured WILL run regardless of which event is active. Events do not affect threads but they can affect other events.

Can anyone explain why this event works but what appears to be an equivalent thread doesn’t?



robot is loading a part onto a gage, which holds the input named Part_accept (analog_in(1)) at +5V unless the part fails, where it drops to zero.

The Event (one of several events in the program) shows up in the program’s script file as:

elif (get_standard_analog_in(1) < 2.0):

    global part_fail=  True  

The Thread shows up as:

thread Thread_1():

if (get_standard_analog_in(1)<2.0):

  global part_fail=  True  


If I suppress the Event and use the thread, it completely ignores the part failure.
If I suppress the thread and use the Event, it works as expected.

I’ve tried sticking a sync() command into the thread, with no effect.

Just confuses me that the thread doesn’t seem to work.