Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > equivalent to Tcl 'after' command?

Reply
Thread Tools

equivalent to Tcl 'after' command?

 
 
Mark Harrison
Guest
Posts: n/a
 
      04-22-2004
I'm writing some event-driven programs, and I would like
to do the equivalent of the Tcl 'after' command, e.g.:

after 1000 {puts "one second has elapsed"}

1. What's the most canonical way of doing this?

2. What's the best reference that talks about non-gui event loop
programming in Python?

Many TIA!
Mark

--
Mark Harrison
Pixar Animation Studios
 
Reply With Quote
 
 
 
 
Jeff Epler
Guest
Posts: n/a
 
      04-22-2004
Python doesn't define any event loop of its own. asyncore has one, but
I don't think it has the concept of scheduling events at a future time,
but only of reacting to the readability / writability of sockets.

I'm sure that more advanced systems, like Twisted, can do the kind of
thing you're asking for.

Jeff

 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      04-22-2004
> after 1000 {puts "one second has elapsed"}
>
> 1. What's the most canonical way of doing this?
>
> 2. What's the best reference that talks about non-gui event loop
> programming in Python?


Has been a while since I used tcl/tk, so I'm a bit rusty here. But AFAIK
that after stuff was needed when the tk event loop took over control. Sooo
- _if_ you use a toolkit, it most probably features such a facility.

In python, such stuff is usually accomplished using threads - and since a
recent version, there is the module sched. Which internally uses threads. I
personally ripped the webware taskkit for recurrent tasks.
--
Regards,

Diez B. Roggisch
 
Reply With Quote
 
Roy Smith
Guest
Posts: n/a
 
      04-22-2004
In article <huThc.54272$(E-Mail Removed)> ,
Mark Harrison <(E-Mail Removed)> wrote:

> I'm writing some event-driven programs, and I would like
> to do the equivalent of the Tcl 'after' command, e.g.:
>
> after 1000 {puts "one second has elapsed"}


You want to took at the Timer objects that are part of the threading
module

http://www.python.org/doc/current/li...r-objects.html
 
Reply With Quote
 
Peter Hansen
Guest
Posts: n/a
 
      04-22-2004
Jeff Epler wrote:

> Python doesn't define any event loop of its own. asyncore has one, but
> I don't think it has the concept of scheduling events at a future time,
> but only of reacting to the readability / writability of sockets.
>
> I'm sure that more advanced systems, like Twisted, can do the kind of
> thing you're asking for.


It does, using reactor callLater(), but I'd go for the sched approach
if it's just a one-off.
 
Reply With Quote
 
Alan Gauld
Guest
Posts: n/a
 
      04-22-2004
On Thu, 22 Apr 2004 17:42:37 GMT, Mark Harrison <(E-Mail Removed)>
wrote:
> I'm writing some event-driven programs, and I would like
> to do the equivalent of the Tcl 'after' command, e.g.:
>
> after 1000 {puts "one second has elapsed"}
>
> 1. What's the most canonical way of doing this?


I suspect its to start a thread that in turn starts with
a sleep command. Not very pretty but approximately the same.

> 2. What's the best reference that talks about non-gui event loop
> programming in Python?


My book(paperversion only discusses them briefly but its hardly a
rference, more an intro to the convcept for beginners...

Its not quite the same as a pure event loop environment but you
could check out the cmd module for a text based command loop/menu
system. If you haven't already....

HTH,

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
 
Reply With Quote
 
Jeff Epler
Guest
Posts: n/a
 
      04-23-2004
> On Thu, 22 Apr 2004 17:42:37 GMT, Mark Harrison <(E-Mail Removed)>
> wrote:
> > I'm writing some event-driven programs, and I would like
> > to do the equivalent of the Tcl 'after' command, e.g.:
> >
> > after 1000 {puts "one second has elapsed"}
> >
> > 1. What's the most canonical way of doing this?

>

On Thu, Apr 22, 2004 at 11:52:57PM +0100, Alan Gauld wrote:
> I suspect its to start a thread that in turn starts with
> a sleep command. Not very pretty but approximately the same.


But "doing something in about X ms in a thread" and "doing something in
about X ms from the event loop" are different: the latter basically
frees you from worrying about locking, race conditions, and the rest,
because you know it can't run concurrently with arbitrary other code.

Jeff

 
Reply With Quote
 
Giles Brown
Guest
Posts: n/a
 
      04-23-2004
Mark Harrison <(E-Mail Removed)> wrote in message news:<huThc.54272$(E-Mail Removed) .com>...
> I'm writing some event-driven programs, and I would like
> to do the equivalent of the Tcl 'after' command, e.g.:
>
> after 1000 {puts "one second has elapsed"}
>
> 1. What's the most canonical way of doing this?


Not exactly canonical (I certainly haven't used it more than once if that), but
there is the standard library "sched" module.

Giles
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to build a loadable tcl dll with visual studio (microsoft C compiler)?[crosspost in comp.lang.tcl and comp.lang.c++] Michael Reichenbach C++ 5 02-08-2010 02:38 PM
TCL scripting or "dialer-watch" equivalent for GRE tunnels? Robert Cisco 5 02-13-2008 01:46 PM
Equivalent of TCL's "subst" ? gamename Python 4 11-17-2007 07:11 PM
Inline::Tcl vs. Inline::Tcl Mumia W. Perl Misc 0 08-23-2006 04:09 PM
Tcl equivalent for Perl's Win32::OLE, LWP::UserAgent, HTTP::Request, Net::Telnet Vinay Gupta Perl 2 07-27-2004 12:31 PM



Advertisments