[issue12502] 100% cpu usage when using asyncore with UNIX socket

Benjamin Ash report at bugs.python.org
Mon Feb 4 17:31:26 CET 2013


Benjamin Ash added the comment:

After doing a bit more testing, I was able to prevent the problem from occurring in asyncore_test.py with the following patch:

--- /proc/self/fd/11	2013-02-04 11:24:41.298347199 -0500
+++ asyncore_test.py	2013-02-04 11:24:40.393318513 -0500
@@ -19,10 +19,18 @@
         self.bind(sock)
         self.listen(5)
 
-    def handle_accepted(self, sock, addr):
-        print('Incoming connection from %s' % repr(addr))
-        handler = EchoHandler(sock)
+    def handle_accept(self):
+        pair = self.accept()
+        if pair is not None:
+            (sock, addr) = pair
+            print('Incoming connection from %s' % repr(addr))
+            handler = EchoHandler(sock)

Using handle_accept() in my code and remembering to call listen() in my asyncore.dispatcher server's constructor did the trick.

I am not sure if we still have a bug here though, since if the subclass doesn't define  a proper handle_accept() we get into the select() loop and 100% CPU utilization after the initial client connection.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12502>
_______________________________________


More information about the Python-bugs-list mailing list