desmaj committed 32b038b

new branch for working on the memory leak

Comments (0)

Files changed (3)


+""" Defines a Port that can be used as a proper Twisted transport
 import base64
 import logging
 import os
 from orbited import transports
+DEBUG = True
+if DEBUG:
+    import objgraph
 def setup_site(port):
     root = resource.Resource()
     static_files = static.File(os.path.join(os.path.dirname(__file__), 'static'))
         self.listening = False
     def startListening(self):
+        """ Called when the reactor starts; starts the Port listening.
+        """
         if not self.listening:
             self.listening = True
 class TCPConnectionResource(resource.Resource):
+    """ Implements the comet session handling logic.
+    """
     pingTimeout = 30
     pingInterval = 30
     logger = logging.getLogger('orbited.cometsession.TCPConnectionResource')
     def ack(self, ackId):
         self.logger.debug('ack ackId=%s'%(ackId,))
+        self.logger.debug('before ack unackQueue=%r'%self.unackQueue)
         ackId = min(ackId, self.packetId)
         if ackId <= self.lastAckId:
             if isinstance(data, TCPClose):
                 # Really close
                 self.close("close acked", True)
+        self.logger.debug('after ack unackQueue=%r'%self.unackQueue)
         self.lastAckId = ackId
     def sendMsgQueue(self):
         return self.connections[path]
     def removeConn(self, conn):
+        self.logger.debug("before removeConn: %s",
+                          len(objgraph.by_type(TCPConnectionResource)))
         if conn.key in self.connections:
             del self.connections[conn.key]
+        self.logger.debug("after removeConn: %s",
+                          len(objgraph.by_type(TCPConnectionResource)))
     def connectionMade(self, conn):
 if __name__ == "__main__":
+    # Let's illustrate the benefit of using the Port. Here we're using an
+    # implementation of the normal twisted protocol with the comet session
+    # Port. It looks the same way that we would use any protocol with
+    # a TCP port, but the transport is a comet connection and not the
+    # usual TCP connection.
     class EchoProtocol(Protocol):
         def dataReceived(self, data):


         help="run Orbited on port 8000 and MorbidQ on port 61613"
+    parser.add_option(
+        "-m",
+        "--manhole",
+        dest="manhole_port",
+        action="store",
+        default=None,
+        help="start a twisted.manhole telnet server on this port"
+    )
+    parser.add_option(
+        "--manhole-password",
+        dest="manhole_password",
+        action="store",
+        default="secret",
+        help="use the argument as the password for the manhole server account 'admin'"
+    )
     (options, args) = parser.parse_args()
     if args:
             logger.error('Aborting; You must define a user (and optionally a group) in the configuration file.')
+    if options.manhole_port:
+        from twisted.manhole import telnet
+        def createShellServer():
+            manhole_port = int(options.manhole_port)
+            factory = telnet.ShellFactory()
+            port = reactor.listenTCP(manhole_port, factory)
+            factory.username = 'admin'
+            factory.password = options.manhole_password
+            print "Manhole listening on port %s", manhole_port
+            return port
+        reactor.callWhenRunning(createShellServer)
     if options.profile:
         import hotshot
         prof = hotshot.Profile("orbited.profile")


 from twisted.web import server, resource
 from twisted.internet import defer, reactor
+DEBUG = True
+if DEBUG:
+    import objgraph
 logger = logging.getLogger('orbited.transports.base.CometTransport')
 class CometTransport(resource.Resource):
     def __init__(self, conn):
+        logger.debug('new transport: %s [%s]',
+                     self.__class__,
+                     len(objgraph.by_type(self.__class__)))
         self.conn = conn = False
         self.closed = False
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.