[Twisted-Python] Getting Rid of Application in a Compatible Way

Glyph Lefkowitz glyph at twistedmatrix.com
Mon Jun 16 05:45:24 MDT 2003


(This is in reply to a message sent last month, so apologies if it 
doesn't thread properly.)

On Friday, May 23, 2003, at 02:02 AM, Moshe Zadka wrote:

> class TCPListener(ApplicationService):

I want to implement this, and also to move ApplicationService into its 
own module and rename it (commensurate with cred changes) - 
twisted.internet.service.Service

>     def __init__(self, port, factory, backlog=5, interface='', *args, 
> **kwargs):
...
>     def startService(self):
>         ApplicationService.startService(self)
>         self._port = reactor.listenTCP(self.port, self.factory, 
> self.backlog,
>                                        self.interface)

This is great, except for the fact that UNIX likes to make it so that 
only root can bind ports, and that would be way too much work to run in 
a privileged mode.  We need to separate initializeService() (which runs 
with privileges) and startService() (which runs without).  This would 
replace bindPorts().

> TCPListener(8080, server.Site(resource), 
> "foo").setServiceParent(application)

The 'setServiceParent' seems a little unweildy.  Why not in the 
__init__?

> The only problem is needing to choose unique names.

Rather than use the opaque key you suggest, which would be potentially 
confusing to sysadmins, we could use a simple sequence number?  Putting 
sequence number generation into Application is probably not such a bad 
idea anyway.

I would really like this refactoring to happen soon, because 
Application is an ungodly mess.  So, to sum up -

	* move Service to new module
	* write TCPListenerService, SSLConnectService, etc
	* write backwards-compatible listen|connectTCP/SSL/etc
	* update _all_ uses of app.(listen|connect)(TCP|SSL|UNIX) in Twisted.
	* write upgrade function to upgrade Application's mutable state.

Does anybody feel like doing something like this?





More information about the Twisted-Python mailing list