Regarding Threads and locals()

Discussion in 'Python' started by Teja, Mar 20, 2008.

  1. Teja

    Teja Guest

    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

    EG:
    ----------------------
    main.py
    --------------------------
    class WorkerThread(threading.Thread):

    def __init__(self, ):
    threading.Thread.__init__(self)
    # Start the thread and invoke the run method
    self.start()

    def run(self):
    # Start the thread. It executed self.func() as a separate
    thread
    self.workerThread, tid = win32process.beginthreadex(None,
    0 , self.func ,(), 1)
    .......

    def func(self):
    execfile(temp.py)

    class GUI(wxFrame):
    def __init__(self):
    .....
    .....
    def CreateThread(self):

    self.workerThread = WorkerThread()


    if name == _main_:
    .....
    .. ....
    .. .....
    ---------------------
    temp.py
    ------------------
    i = 1
    j = 2
    k = 4
    while(10000):
    print i
    print j
    print k
    i = 1+1
    j = j+2
    k = k + 3


    Now, while the thread is executin func and printing i, j, k , In the
    main GUI thread how do i get the values of i, j ,k
    I tried with sys.modules, sys._current_frames, vars(). But nothing
    worked out.

    Ideally the locals() of func() should be passed to the GUI thread,
    how?
     
    Teja, Mar 20, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Olivier Sessink
    Replies:
    0
    Views:
    389
    Olivier Sessink
    Feb 24, 2005
  2. JerryB

    locals() and dictionaries

    JerryB, Feb 1, 2006, in forum: Python
    Replies:
    4
    Views:
    323
    Kent Johnson
    Feb 2, 2006
  3. Josiah Carlson
    Replies:
    4
    Views:
    355
    Boris Borcic
    Jun 19, 2006
  4. Paolo Pantaleo

    locals() and globals()

    Paolo Pantaleo, Oct 14, 2006, in forum: Python
    Replies:
    1
    Views:
    583
    Kay Schluehr
    Oct 14, 2006
  5. rocksportrocker

    problem with exec and locals()

    rocksportrocker, Jul 1, 2008, in forum: Python
    Replies:
    4
    Views:
    292
    Gabriel Genellina
    Jul 11, 2008
Loading...

Share This Page