[Twisted-Python] Ampoule - 0.0.2

Valentino Volonghi dialtone at gmail.com
Sat Sep 27 01:42:45 MDT 2008

I just released Ampoule 0.0.2 on pypi and launchpad


Ampoule is a process pool implementation written
on top of Twisted Matrix. Its name comes from the
use of AMP as the default communication protocol
between the pool and all its children.

It's different from other alternative solutions because it
provides an API very close to that of the Twisted ThreadPool.
As an helper function it also provides a deferToAMPProcess
function that creates the ProcessPool and submits jobs to it.

The code is pretty well tested, in fact it contains more test lines
than actual code lines, and it's pretty well documented.

Speedwise on my macbook pro I was able to run about 1700 Ping
calls per second without recycling processes and about 1500 with
a recycling value of about 10000 calls per process.
If anyone wants to contribute a C implementation of amp
serializer/deserializer I'm pretty sure that Ampoule would benefit a
lot from it but for my current tasks 1500 calls per second is more
than fast enough, it's actually pretty fast.

A usage example is the following:

from ampoule import child, util
from twisted.protocols import amp

class Pid(amp.Command):
     response = [("pid", amp.Integer())]

class MyChild(child.AMPChild):
     def pid(self):
         import os
         return {"pid": os.getpid()}

def main(args):
     import sys
     from twisted.internet import reactor, defer
     from twisted.python import log

     from ampoule import pool

     def _run():
         pp = pool.ProcessPool(MyChild)
         yield pp.start()
         result = yield pp.doWork(Pid)
         print "The Child process PID is:", result['pid']
         yield pp.stop()

     reactor.callLater(1, _run)

What's new in this version:

Ampoule 0.0.2 (2008-09-26)

  - Support process recycling after predefined number of calls.

  - ProcessPool argument max_idle is now maxIdle to comply with Twisted
    style guidelines.

  - removed ampoule.runner module because it was essentially useless,
    if you want to change subprocess startup behavior pass a string that
    contains the new code as an argument by overriding the default
    processFactory for example with a closure like this:

        from ampoule.main import startAMPProcess
        from ampoule.pool import ProcessPool
        pp = ProcessPool()
        def myProcessFactory(*args, **kwargs):
            kwargs['bootstrap'] = myBootstrapCode
            return startAMPProcess(*args, **kwargs)
        pp.processFactory = staticmethod(myProcessFactory)

Have fun with ampoule! :)

Valentino Volonghi aka Dialtone
Now running MacOS X 10.5
Home Page: http://www.twisted.it

-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20080927/989e1970/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 194 bytes
Desc: This is a digitally signed message part
URL: </pipermail/twisted-python/attachments/20080927/989e1970/attachment.sig>

More information about the Twisted-Python mailing list