I'm trying to implement some custom blocks to help teach parallel programming and I have a few questions.
First, to import the threading library, it looks like I would include threading in the list of reserved words (as in math.js in generators/python) with
Blockly.Python.addReservedWords('threading');
Then am I to include something like
Blockly.Python.definitions_['import_threading'] = 'import threading';
in every block that uses threading?
Next, as an example, I'd like to create a SummingThread block that takes two inputs.
class SummingThread(threading.Thread):
def __init__(self,low,high):
threading.Thread.__init__(self)
self.low=low
self
self.high=high
self
self.total=0
def run(self):
for i in range(self.low,self.high):
self.total+=i
thread1 = SummingThread(0,500000)
thread2 = SummingThread(500000,1000000)
thread1.start() # This actually causes the thread to run
thread2.start()
thread1.join() # This waits until the thread has completed
thread2.join()
# At this point, both threads have completed
result = thread1.total + thread2.total
print result
I'm not sure how to get started creating a generator to do this -- specifically making a generator to work with classes. Any help is appreciated!