[Answer]-Dynamic array inside a for statement

1👍

You can use treading to get threads that process or sub-process your high priority data with Queue, as said by WhozCraig.
Here’s an example of how it could look like. If you want to use multiple threads and more functions than only run() you will have to redefine the thread object calling from thread1_high_priority = High_priority_Thread(1, 10, queue)# where the parameters are defined in run() to
thread1_high_priority = High_priority_Thread(target= functionname, name = name)# and the same in init, def init (self, target, name):.

import Queue
import threading
import time


queue = Queue.Queue()

class High_priority_first(threading.Thread):
    """ a threading class"""

    def __init__ (self, start, stop, queue):


        self.start = start
        self.stop = stop
        self.queue = queue
        threading.Thread.__init__(self)

# Write a function, run(), that counts the higher priority data and extend it to
# also count lower priority, or create another function for low priority data and
# run them with a separate thread than thread 1.

    def run(self):
        while True:
            if self.start != stop:
                self.start += 1
                self.queue.put(self.start)

            else:
                break


thread1_high_priority = High_priority_Thread(1, 10, queue)# start at 1 and stop at 10
thread1_high_priority.start() #start thread1

thread2_lower_priority = High_priority_Thread(1, 3, queue)# start at 1 and stop at 3
thread2_lower_priority.start() #start thread2

while True:
    if queue != None: # check that queue isn't empty
        out =  queue.get()
        print out

    else:
        break

Leave a comment