[Tkinter-discuss] Fw: Tkinter's createfilehandler - attempt to run parallel threads

Sorin Schwimmer sxn02 at yahoo.com
Thu Oct 12 17:45:19 CEST 2006


This question was posted on python-list at python.org, but found no answer there. Maybe here I'll be lucky...

Thanks,
Sorin

----- Forwarded Message ----
From: Sorin Schwimmer <sxn02 at yahoo.com>
To: python-list at python.org
Sent: Thursday, July 27, 2006 1:20:21 PM
Subject: Tkinter's createfilehandler - attempt to run parallel threads

Hi,

The project that I'm working for runs a PostgreSQL database on a remote machine and several Python clients all over the place. The objects usualy have in their constructor a query to the database. As the query is executed on the remote machine, I'm trying to be fancy and execute it while building my Tkinter interface.

The following code illustrates what I'm attempting to do:

<code>
#! /usr/bin/python

from pg import DB
from Tkinter import *

class thrd:
  def __init__(s,r):
    print 'Executing __init__'
    db=DB('design',host='xx.xx.xx.xx',user='yyyy') # relevant IP and user needed
    print 'db=DB(...'
    tkinter.createfilehandler(db,tkinter.READABLE|tkinter.WRITABLE,s.th)
    print 'createfile...'
    Label(r,text='Let\'s see the results').grid()
    print 'Label...'
   
 s.b=Button(r,text='GO')
    print 's.b=Button...'
    s.b.bind('<Button-1>',s.rslt)
    print 's.b.bind...'
    s.b.grid()
    print 's.b.grid()'
    print '__init__ done'

  def th(s,db,msk):
    print '->Executing th'
    s.r=db.query('select * from customers limit 10').getresult() # some query
    print '->s.r=...'
    tkinter.deletefilehandler(db)
    print '->deletefile...'
    db.close()
    print '->db.close()'
    print '->th done'

  def rslt(s,e):
    for i in s.r:
      print i

if __name__=='__main__':
  r=Tk()
  t=thrd(r)
  r.mainloop()
</code>

The output is:Executing
 __init__

<code>
db=DB(...
createfile...
Label...
s.b=Button...
s.b.bind...
s.b.grid()
__init__ done
->Executing th
->s.r=...
->deletefile...
->db.close()
->th done
</code>

and it basicly shows that everything happens sequentialy. Pressing the button gives the expected result, so everything is correct. How can I obtain the desired parallelism?

Thanks,
Sorin
 
		
Groups are talking. We´re listening. Check out the handy changes to Yahoo! Groups. 




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20061012/74514c78/attachment.htm 


More information about the Tkinter-discuss mailing list