Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement a long-running, event-driven python program?

Tags:

python

I have a series of maintenance tasks for a python WSGI application that are a bit too complex for a crontab (jobs need to be run at frequencies derived from the size of the job queue, manage a connection pool to a group of EC2 instances, etc).

How should I implement a long-running, event-driven python program? I've never needed this functionality before, so I'm not even sure what to google.

like image 292
Parker Ault Avatar asked Aug 29 '11 23:08

Parker Ault


People also ask

What do you mean by event-driven programming explain the method of implementing it in Python?

The working of Event-Driven programming depends upon the events happening in a program. Other than this, it depends upon the program's event loops that always listen to a new incoming event in the program. Once an event loop starts in the program, then only the events will decide what will execute and in which order.

Where is event-driven programming popularly used in Python?

Event-driven programming focuses on the events (messages) and their flow between different software components. In fact, it can be found in many types of software. Historically, event-based Python programming is the most common paradigm for software that deals with direct human interaction.


1 Answers

Most of the large, modern python sites are using Celery for this type of work. It is a distributed task queue that supports scheduling of tasks as well.

Though probably a bit heavyweight for a small site, it'll grow with you. I'm looking to implement it myself (sans Rabbit) shortly.

I recently found another choice for django users, django-tasks which is focused on fewer, longer, batch processing type jobs. There is also django-ztask using zeromq.

Addendum: Just came across gearman which has python bindings.

like image 181
Gringo Suave Avatar answered Sep 20 '22 23:09

Gringo Suave