theads & global namespaces
Eric Lee Green
e_l_green at hotmail.com
Wed Jun 30 19:20:15 EDT 1999
Taylor Anderson wrote:
> I am trying to share globals between threads. Is is possible for me to
> share globals between threads that call functions from different
> modules?
I solved that problem by introducing a module "depository" that has my
"global" stuff that I want shared between threads. It is full of lines like
"hash_table={}" and so forth. Then in my modules I just
import depository
and down further, to access my "global" hash_table,
names=depository.hash_table.keys() # get list of keys in hash table for
expire purposes
and voila.
Yes, it works across threads. Just make sure to properly use semaphors if you
are doing operations on multiple structures (e.g., if I had two tables
"hash_table" and "hash_table_weights" and needed to keep them in sync). You
may wish to create some helper functions in your depository module to handle
the locking/setting/retrieving of such structures.
--
Eric Lee Green eric at estinc.com
SysAdmin/Software Engineer Visit our Web page:
Enhanced Software Technologies, Inc. http://www.estinc.com/
(602) 470-1115 voice (602) 470-1116 fax
More information about the Python-list
mailing list