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

  • Home
  • SEARCH
  • 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 136211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:54:45+00:00 2026-05-11T06:54:45+00:00

So i’m toying around with stackless python, writing a very simple webserver to teach

  • 0

So i’m toying around with stackless python, writing a very simple webserver to teach myself programming with microthreads/tasklets. But now to my problem, when I run something like ab -n 100000 -c 50 http://192.168.0.192/ (100k requests, 50 concurrency) in apache bench I get something like 6k req/s, the second time I run it I get 5.5k, third time 5k, fourth time, 4.5k, etc. all the way down to 100req/s or something.

The problem goes away when I restart the python script, though.

Now my question is why? Am i forgetting to delete tasklets? I’ve checked the stackless.getruncount() (and it always seems to return 1, for some reason) so it doesn’t seem like there would be any dead tasklets hanging around? I’ve tried calling .kill() on all tasklets that are done, didn’t help. I just can’t figure this one out.

import socket import select import stackless import time  class socket_wrapper(object):     def __init__(self, sock, sockets):         super(socket_wrapper, self).__init__()         self.sock = sock         self.fileno = sock.fileno         self.sockets_list = sockets         self.channel = stackless.channel()         self.writable = False         self.error = False      def remove(self):         self.sock.close()         self.sockets_list.remove(self)      def send(self, data):         self.sock.send(data)      def push(self, bytes):         self.channel.send(self.sock.recv(bytes))  def stackless_accept(accept, handler, recv_size=1024, timeout=0):     sockets = [accept]      while True:         read, write, error = select.select(sockets, sockets, sockets, timeout)          for sock in read:             if sock is accept:                 # Accept socket and create wrapper                 sock = socket_wrapper(sock.accept()[0], sockets)                  # Create tasklett for this connection                 tasklet = stackless.tasklet(handler)                 tasklet.setup(sock)                  # Store socket                 sockets.append(sock)              else:                 # Send data to handler                 sock.push(recv_size)          # Tag all writable sockets         for sock in write:             if sock is not accept:                 sock.writable = True          # Tag all faulty sockets         for sock in error:             if sock is not accept:                 sock.error = True             else:                 pass # should do something here if the main socket is faulty          timeout = 0 if socket else 1         stackless.schedule()   def simple_handler(tsock):     data = ''      while data[-4:] != '\r\n\r\n':         data += tsock.channel.receive()      while not tsock.writable and not tsock.error:         stackless.schedule()      if not tsock.error:         tsock.send('HTTP/1.1 200 OK\r\nContent-length: 8\r\n\r\nHi there')         tsock.remove()  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind(('192.168.0.192', 8000)) sock.listen(5)  stackless.tasklet(stackless_accept)(sock, simple_handler) stackless.run() 
  • 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. 2026-05-11T06:54:46+00:00Added an answer on May 11, 2026 at 6:54 am

    Two things.

    First, please make Class Name start with an Upper Case Letter. It’s more conventional and easier to read.

    More importantly, in the stackless_accept function you accumulate a list of Sock objects, named sockets. This list appears to grow endlessly. Yes, you have a remove, but it isn’t always invoked. If the socket gets an error, then it appears that it will be left in the collection forever.

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

Sidebar

Ask A Question

Stats

  • Questions 98k
  • Answers 98k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer seems like I found the solution. Seems to be the… May 11, 2026 at 7:33 pm
  • Editorial Team
    Editorial Team added an answer Based on my tests here, properties from categories will show… May 11, 2026 at 7:33 pm
  • Editorial Team
    Editorial Team added an answer I found a solution that sort of works... add the… May 11, 2026 at 7:33 pm

Related Questions

So I'm getting a new job working with databases (Microsoft SQL Server to be
So I have a Sybase stored proc that takes 1 parameter that's a comma
So I'm embarking on an ASP.NET MVC project and while the experience has been
So I've got a JPanel implementing MouseListener and MouseMotionListener : import javax.swing.*; import java.awt.*;
So I wrote some perl that would parse results returned from the Amazon Web

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.