shared info: safety and performance questions

nathan at islanddata.com nathan at islanddata.com
Sun May 2 17:42:35 EDT 1999


I have some questions regarding safety and performance of shared
variables.  The situation: I'm writing a multithreaded, event-driving
GUI application.  Some events create new threads, but all GUI calls
are handled in the main thread, so no worries there.  First, safety:

I don't want to deal with semaphores/mutexes/etc. unless necessary.
What python commands are considered atomic and threadsafe?  I would
especially be interested in append() and del being safe, as well as
mutation of lists and dictionaries through reassignment.

Next, performance.  Functions in different threads and idlefuncs need
to share data.  One func might need list a, another might need dict b,
another may need tuple c, and another might need a and c but not b.
Would it be faster to send each mutable variable where it belongs, or
stuff them all in a giant dictionary which gets passed to each shared
function regardless of its need, which looks up only the appropriate
keys?

Thanks for the help!





More information about the Python-list mailing list