Concurrency models (was: Timer)

Alex Martelli aleax at aleax.it
Tue Oct 28 10:03:48 EST 2003


Cameron Laird wrote:

> In article <ycsnb.57562$e5.2124785 at news1.tin.it>,
> Alex Martelli  <aleax at aleax.it> wrote:
> .
> .
> .
>>Note that, in Python, you have that 'after' available any time
>>you're running a Tkinter GUI: any Tkinter widget has an 'after'
>>method that takes a delay (in milliseconds), a callable object,
>>and optionally some arguments, and schedules the callable to
>>be called with those arguments after that delay.
>>
>>It works a charm, btw.
> .
> .
> .
> I want to refine Alex' description:  it's possible to
> use after with only the slenderest connection to a
> Tkinter GUI.  You can "import Tkinter", and exploit
> after(), without ever having to make Tkinter widgets
> or windows visible on the screen.

and I'll further refine yours: "as long as you run
Tkinter's mainloop".  Yes, you can hide Tkinter's root
window and still run its mainloop (I think you have
to be explicit about it though:-), as long as you don't
need any of the normal processing flow used by most
non-GUI applications (including other event-driven apps
that don't use Tkinter's mainloop -- e.g., network ones
that use asyncore or select).  And the .after callback
will be able to get into play only if other callbacks
(presumably also from .after, if you have no GUI) return
reasonably promptly.

In short, I doubt using Tkinter just for the sake of
getting .after makes much sense -- you're probably at
least as well off with the much lighter-weight scheduler
module, in that case.  (OTOH, if it IS possible to
give fileobjects to Tkinter to cause callbacks when
they're ready, as it is in Tcl/Tk, then using Tkinter
w/o GUI may indeed be easier than merging e.g scheduler
and select -- it depends... but last time I checked I
saw no way to get the "callback on file activity" from
Tkinter as I could back when I used Tcl/Tk...).


Alex





More information about the Python-list mailing list