Close

THREADS! AH

A project log for Real Tricorder: With Scanny Bits (TNG)

goal: build a photo realistic and functional tricorder from tng. this means creating custom PCBs w/ chips, firmware/software, and a chassis.

TG-TechieTG-Techie 06/03/2018 at 21:340 Comments

WHOO! just added priority based threading to the triocrder.

what does this mean:

i have made a group of libraries, available  on github *shameless plug* (https://github.com/TG-Techie/TG-Modules), that has two classes. the first is a task class. it make an object with a stored method and a stored tuple. when call the .perform() method on a created task it will execute the tuple as the input for the method stored:

from tg_modules import task

my_obj = task(print, ("text to be printed"))

my_obj.perform()

would output:

text to be printed

the next class is a thread_list class:

this class allows you to add tasks with an assigned priority:

so items with a lower priority number are executed first.

from tg_modules import thread_list

my_list = thread_list(length = 3)

my_list.add_task(print,('world'),priority = 3)
my_list.add_task(print,('hello'),priority = 1)

my_list.chug() #this works through all the current tasks

this would output:

hello
world

this is b/c the  print('hello') task has a lower priority number

have fun:-)

any questions please ask! (or if messed something up here)

and have a great day 

Discussions