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 6046221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:12:50+00:00 2026-05-23T07:12:50+00:00

When I use the eventlet package to run a multi-coroutines task, even when the

  • 0

When I use the eventlet package to run a multi-coroutines task, even when the coroutines pool is empty, the program won’t continue to run, but will get stuck in a loop. Following is my code and the last row never get executed.

import eventlet

global count
post_id=[]
last_id=0

def download(post_id):
    global count
    print "coroutines :",post_id
    if count<last_id:
        count=count+1
        q.put(count) # put new coroutines  in the queue


pool = eventlet.GreenPool()
q = eventlet.Queue()

for i in range(100,200):
    post_id.append(i)

for i in range(0,5):
    q.put(post_id[i]) # keep 6 coroutines  in the pool

count=post_id[5]
last_id=200

while not q.empty() or pool.running()!=0:
    pool.spawn_n(download,q.get()) #start corroutines

print "The end" #nerver reach to this line
  • 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-05-23T07:12:50+00:00Added an answer on May 23, 2026 at 7:12 am

    The last row never gets executed because your final call to q.get() blocks forever, waiting for something to be added to the queue. There are a few ways you could fix this, including passing a timeout value to get. I think the cleanest solution is to wait for the current tasks to finish if the queue is empty before attempting another iteration of the loop again:

    while not q.empty():
        pool.spawn_n(download, q.get())
        if q.empty(): pool.waitall()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

use this website a lot but first time posting. My program creates a number
My incomplete understanding is that Twisted, Stackless, Greenlet, Eventlet, Coroutines all make use of
use Rack::Static, :urls => ['/stylesheets', '/images'], :root => 'public' run proc { |env| [200,
Use Case When a user goes to my website, they will be confronted with
Use a hidden field will fix my issue... i got it.. Hi All, I
Use case: we have some project meta-data files which we want tracked, but are
use case is simple: I want to run some boiler plate code before each
use a reapeter to display data, but sometimes the data is to big to
Use new MediaPlayer by Yahoo. Content parse automatic - greate, but I use ajax
Use of rails 3 recaptcha. In view _form.html.erb insert <%= recaptcha_tags %> But when

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.