Re: Deferring a function call

2010-10-19 Thread Werner Thie
For me nothing beats using twisted ( http://www.twistedmatrix.com ) with its clean implementation of deferreds and a host of other useful things for simulations besides being the 'Swiss Army Knife' of networking in Python. If you throw in stackless ( http://www.stackless.com ) simulations with

Re: Deferring a function call

2010-10-19 Thread TomF
Thanks for the ideas, everyone. functools.partial and lambda expressions seem like a more pythonic way of doing what I want. I don't know whether they're actually more efficient or better, but at least they eliminate the need to carry args around separately. I'd forgotten Python has a sched

Re: Deferring a function call

2010-10-19 Thread Peter Otten
TomF wrote: > I'm writing a simple simulator, and I want to schedule an action to > occur at a later time. Basically, at some later point I want to call a > function f(a, b, c). But the values of a, b and c are determined at > the current time. > > One way way to do this is to keep a list of en

Re: Deferring a function call

2010-10-19 Thread Michael Ricordeau
For scheduling, I use eventlet package and spawn_after_local . http://eventlet.net But you must be aware of the constraints like using "monkey patched" modules . Le Mon, 18 Oct 2010 21:21:41 -0700, TomF a écrit : > I'm writing a simple simulator, and I want to schedule an action to > occ

Re: Deferring a function call

2010-10-18 Thread Cameron Simpson
On 19Oct2010 04:59, Steven D'Aprano wrote: | Chris Rebert has already mentioned the sched module. Otherwise, put the | function call in a thread, and have the thread use time.sleep to wait | until the right time to execute. There is also the Timer class from the threading module. Cheers, --

Re: Deferring a function call

2010-10-18 Thread Lawrence D'Oliveiro
In message <2010101821214168010-tomfsess...@gmailcom>, TomF wrote: > One way way to do this is to keep a list of entries of the form [[TIME, > FN, ARGS]...] and at simulated time TIME do: fn(*args) or fn(**kwargs) -- http://mail.python.org/mailman/listinfo/python-list

Re: Deferring a function call

2010-10-18 Thread Steven D'Aprano
On Mon, 18 Oct 2010 21:21:41 -0700, TomF wrote: > I'm writing a simple simulator, and I want to schedule an action to > occur at a later time. Basically, at some later point I want to call a > function f(a, b, c). But the values of a, b and c are determined at the > current time. > > One way wa

Re: Deferring a function call

2010-10-18 Thread Chris Rebert
On Mon, Oct 18, 2010 at 9:21 PM, TomF wrote: > I'm writing a simple simulator, and I want to schedule an action to occur at > a later time.  Basically, at some later point I want to call a function f(a, > b, c).  But the values of a, b and c are determined at the current time. See the `sched` std

Deferring a function call

2010-10-18 Thread TomF
I'm writing a simple simulator, and I want to schedule an action to occur at a later time. Basically, at some later point I want to call a function f(a, b, c). But the values of a, b and c are determined at the current time. One way way to do this is to keep a list of entries of the form [[T