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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:01:33+00:00 2026-06-17T10:01:33+00:00

The code never reaches the print ‘never reach1’ or print ‘never reach2’ line when

  • 0

The code never reaches the print 'never reach1' or print 'never reach2' line when I try to telnet into the server.

import sys, signal
from gevent.server import StreamServer
from gevent.pool import Pool
from gevent import monkey
import gevent
from gevent import Timeout
import random

class SocketPool(object):

    def __init__(self):
        self.pool = Pool(1000)

    def listen(self, socket):
        while True:
            line = socket.recv(1024)
            print line

    def add_handler(self, socket, address):
        if self.pool.full():
            raise Exception("At maximum pool size")
        else:
            self.pool.spawn(self.listen, socket)
            gevent.spawn(self.wait).join()

    def wait(self):
        try:
            timeout = Timeout(1)
            timeout.start()
        except Timeout:
            print 'never reach1'
        except:
            print 'never reach2'

    def shutdown(self): self.pool.kill()

def signal_handler(signal, frame): sys.exit(0)

signal.signal(signal.SIGINT, signal_handler)
monkey.patch_all()
sockPool = SocketPool()
server = StreamServer(('127.0.0.1', 5000), sockPool.add_handler)
server.serve_forever()
  • 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-17T10:01:34+00:00Added an answer on June 17, 2026 at 10:01 am

    As you can see from the documentation:

    timeout = Timeout(seconds, exception)
    timeout.start()
    try:
        ...  # exception will be raised here, after *seconds* passed since start() call
    finally:
        timeout.cancel()
    

    So your try block is completely executed and hence cannot catch the exception.
    You should put something like a while loop or a computation that requires at least 1 second to see the exception.

    If you want to make a method that simply "sleeps" without using CPU I’d recommend using a simple time.sleep instead of using a Timeout.

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

Sidebar

Related Questions

I have never used Try-catch in my code before, but now I need to
Why this code only shows cmd window and never reaches the end ? I
For some reason, the following code never calls Event::Event(Event&& e) Event a; Event b;
I have never code in Python and trying to switch from Javascrpt/SVG. Being confused
I've never seen code like this: public static function getInstance() { if ( !
I think back to Joel Spolsky's article about never rewriting code from scratch. To
I have this code that runs but never stops. class A { public static
Never thought I'd have this problem :) The following snippet of code works in
The following code gives seg fault and some time stalls/hangs and never works. for(i=0;i<360;i++)
I've never written Ajax before and I am currently trying to code up an

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.