moving to processing from threading, global variables

rkmr.em at gmail.com rkmr.em at gmail.com
Thu Apr 9 11:05:09 EDT 2009


hi
i am trying to move from threading to processing package. this is the
controller i used to spawn new threads, and it used the global
variable done to check if it needs to spawn more threads or not. it worked
great for me. it checks if there is new data to be processed every
30 seconds, and spawns of new threads to do the work, till all work is done.


but now in processing, anychange made to global variable done in sendalert
method, is not reflected in the controller method.

can please point out what is wrong?
thanks a lot!


code


done = False
def sendalert():
   global done
   users = q.get('xx')
   if not users:
     done = True
     return

   done = False
   for u in users:
    do stuff


def control(number_threads_min=3, number_threads_max = 100):
    global done
    while True:
        number_threads = len(processing.activeChildren())
        if not done and number_threads<number_threads_max:
            processing.Process(target=sendalert).start()
        if done and number_threads<number_threads_min:
            processing.Process(target=sendalert).start()
            time.sleep(30)

if __name__ == '__main__':
    processing.Process(target=control).start()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090409/6b6daf29/attachment.html>


More information about the Python-list mailing list