event loops and Python?

David Arnold arnold at dstc.edu.au
Sun Mar 12 07:19:03 CET 2000


-->"Kragen" == Kragen Sitaker <kragen at dnaco.net> writes:

  Kragen> Sorry, I meant, "This is bad if you're not running in a
  Kragen> graphical environment."  I want to build an event-driven tty
  Kragen> application.

  Kragen> I guess I should start looking at how Tkinter does it :)

i think tk uses the underlying Xt mainloop.  this is a part of the
standard X distribution.  similar things are done by Gtk, for example.

all it involves is a top-level loop based around select().  select
takes a list of file objects and an (optional) timeout.  it will wait
for activity on one of the files, or the expiry of the timeout, before
returning control to your code.

using this, you can monitor network connections, ttys, etc and
implement timers for delayed functions or regular checks, etc.

you can easily do this all in Python (on Unix.  win32's select()
doesn't work for anything other than sockets, and you'll have to use
WaitForMultipleObjects() or something).

it's not clear exactly what you want to do, but a quick cruise of the
X or Gtk (actually, i think it's in the GDK) mainloops will get you
started.


d





More information about the Python-list mailing list