moving to processing from threading, global variables

MRAB google at mrabarnett.plus.com
Sun Apr 12 20:46:13 CEST 2009


rkmr.em at gmail.com wrote:
> no one?

It's Easter! :-)

> how can i share variables in processing?
> please help out!
> 
Threads run in the same address space, so they can share variables;
processes run in different address spaces, so they can't (normally).

You'll need to read the documentation carefully to see what the
recommended techniques are (and I doubt that sharing a global Boolean
variable is one of them...).

> On Thu, Apr 9, 2009 at 8:05 AM, rkmr.em at gmail.com 
> <mailto:rkmr.em at gmail.com> <rkmr.em at gmail.com 
> <mailto:rkmr.em at gmail.com>> wrote:
> 
>     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()
> 
> 
> 
> ------------------------------------------------------------------------
> 
> --
> http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list