Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9221259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:32:22+00:00 2026-06-18T03:32:22+00:00

In my Django web app, I have a worker program that is a client

  • 0

In my Django web app, I have a worker program that is a client of a rate-limited API and is responsible for handling all requests to that API from my server threads. I use my database to store the task queue. Tasks can come in large bunches, or not at all. I’m using an event loop to poll the queue and manage delay in between tasks, in case the rate-limit is exceeded (the limit is dynamic). This all works fine, but the only other thing I want to do is to have a way for the worker to stop hitting the database if the queue goes dry, and a way for my Django app to signal the worker that the queue is no longer dry again.

Schematically, in pseudo-Python it looks like this:

state = NORMAL
delay_time = NORMAL_DELAY

while True:
    sleep(delay_time)

    if state == DORMANT:
        continue

    task = get_next_task() # hits database
    if task is None:
        state = DORMANT
        delay_time = NORMAL_TIME

    try:
        execute(task)
    except RateExceeded:
        delay_time = backoff(delay_time)
    else:
        delay_time = NORMAL_DELAY

# Triggered by web layer
def asynchronous_event():
    state = NORMAL

And I either want an asynchronous event triggered from the web layer that can set state back to NORMAL (which would execute during sleep) or some other lightweight check that won’t add needless looped DB queries.

In a single-machine setup, I could just use signals, but obviously this doesn’t work in a multi-machine setup. I’m trying not to have to run a separate message queue server just for the purpose of this one signal. I’m hosted on Dotcloud, in case that plays into what network-based solutions would work. Ideally, something more or less equivalent in ease of implementation as a signal handler. I’ve looked into ZeroRPC, but I’m not sure how to incorporate it into my event loop.

Any ideas?

Edit

I’m looking into ZeroMQ to solve this problem, but I could use some help. The tricky part is that there will be multiple concurrent webserver instances, and upon redeployment, I need for there to be a smooth transition from one worker to its successor. So, bear with me, because my terminology is probably not correct, it seems to me that the best thing to do is have each worker bind asynchronously to an address as a mailbox, which gets checked in the main loop to wake up from dormant mode. Each worker creates a record in the database of its IP, timestamped with creation date. When submitting a request, the web server publishes a message to all workers. When a worker receives a message, it checks if its the worker with the latest creation date: if so, it processes the message, and if not, it terminates itself.

It seems like a lot of trouble, but I want to get this right because I will likely be using this paradigm elsewhere in my application.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:32:24+00:00Added an answer on June 18, 2026 at 3:32 am

    As it turned out, I decided just to hit the database every loop through. But I also decided that ZeroMQ is the way to go if I ever want to put in the effort to make this really efficient. Here’s how it works:

    Each worker binds a ZeroMQ subscriber socket and registers itself in a database of workers, which contains the IP address and port of the socket. The web threads publish a DO_TASK message to the most recently registered worker and QUIT messages to any others that might be working.

    I’m deploying on Dotcloud, and their support says that using the custom service environment variables and build options will let me open the necessary ports and get the IPs of the worker task instances.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Django web app that I would like to use in a
I have a URL in a Django based web app that looks similar to
I have a django web app with a RESTful API written using TastyPie. I
I have an existing django web app that is in use. I have to
I have a reviews/ratings web application, a la Digg. My django app content has
I have a Django webapp that has both a front-end, web-accessible component and an
I have recently switched to Django for a web app I'm developing and I
Business: Practical background for all that is design of web-app, where web-page constructed from
I created a web app with Django and I have it running on localhost
I am working on a web-app using Django 1.3 and Python2.6. I have to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.