Blockly for Parallel Programming in Python -- Getting Started

350 views
Skip to first unread message

ADYoung

unread,
Jan 18, 2014, 6:21:45 PM1/18/14
to blo...@googlegroups.com
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!

Message has been deleted

SuzannePK

unread,
Jan 19, 2016, 8:08:37 PM1/19/16
to Blockly
Did you ever get this to work? I am trying to find content for a 100 girls of code event that will use a cluster. 
Reply all
Reply to author
Forward
0 new messages