[python-win32] Regarding Threads and locals()

Tim Roberts timr at probo.com
Thu Mar 20 18:22:49 CET 2008

Tejovathi P wrote:
> Hi all,
> I have a GUI applicaion(along with threads). When the run button is 
> pressed in the GUI a separate thread starts( Thread is created using 
> beginthreadex) and does the
> required activity.
> Now, while the thread is being executed, i want the locals() present 
> inside the thread's run function to be avaialbe in the GUI class from 
> where the thread class is being created

Why do you use execfile for this?  That seems very odd to me.  Also, why 
use beginthreadex instead of the native Thread module?

Adding threading doesn't really change this problem.  Just think about 
how you'd solve it without threading: by creating a class and using import:


class Handler():
  def run():
    self.i = 1
    self.j = 2
    self.k = 4
        print i
        print j
        print k
        self.i = 1+1
        self.j += 2
        self.k += 3


    def func(self):
        import temp
        self.thread = temp.Handler()

Now, the rest of the GUI can examine self.thread.i, self.thread.j, and 
self.thread.k.  There are locking issues here, but that's left as an 
exercise for the reader.

That's probably not the perfect solution, but it gives you the general 

Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.

More information about the python-win32 mailing list