On Sun, Jul 3, 2011 at 6:10 AM, Stéphane Klein <[email protected]> wrote:
> Le 29/06/2011 23:30, Mike Orr a écrit :
>>
>> On Wed, Jun 29, 2011 at 10:40 AM, hisan<[email protected]>  wrote:
>>>
>>> how to call a function for evry 10 secs in python
>>
>> I assume this is a Pylons or Pyramid application since this is
>> pylons-discuss. The easiest way would probably be to start a thread in
>> the initialization code (environment.py for Pylons, main() for
>> Pyramid). The thread would run a long-running function with a loop
>> that that records its start time, does its thing, sleeps for ``(10
>> seconds - (now - start_time))``, and repeats.
>>
>> Another way to do repeated events is with cron, possibly using "paster
>> request". But that won't work in this case because cron can't handle
>> intervals of less than a minute.
>>
>
> Celery library can't help to do this task ?
>
> http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html

I don't know much about Celery or parallel programming, but it seems
like more software than necessary for a single repeated task. Celery
is more the kind of thing you'd use to replace the main thread pool
with (i.e., in paste.httpserver) -- where you have several different
kinds of messages coming simultaneously from unknown sources. If
you're just repeating a single task, it would be overkill. Also note
that Celery is asynchronous. In order to integrate into a
mulththreaded program (as opposed to replacing the thread pool with an
asynchronous non-pool), you'd have to run it in a separate thread (in
which case my suggestion would be easier), or run the other task (the
one it's sharing the thread with) in Celery too, which would be
difficult to retrofit into an existing threaded application.

-- 
Mike Orr <[email protected]>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to