[Twisted-Python] Getting Rid of Application in a Compatible Way
I suggest to write ApplicationService classes which look like: class TCPListener(ApplicationService): def __init__(self, port, factory, backlog=5, interface='', *args, **kwargs): self.port = port self.factory = factory self.backlog = backlog self.interface = interface ApplicationService.__init__(self, *args, **kwargs) def __getstate__(self): d = self.__dict__.copy() d['_port'] = None return d def startService(self): ApplicationService.startService(self) self._port = reactor.listenTCP(self.port, self.factory, self.backlog, self.interface) def stopService(Self): ApplicationService.stopService(self) self._port.stopListening() self._port = None Now, instead of application.listenTCP we can use TCPListener(8080, server.Site(resource), "foo").setServiceParent(application) The only problem is needing to choose unique names. I suggest ApplicationService will lose the unPythonic if not isinstance(serviceName, types.StringType): raise TypeError("%s is not a string." % serviceName) And add to app.py class Unique: pass This means that "unnamed" services are now possible: TCPListener(8080, server.Site(resource), Unique()).setServiceParent(application) You can still access a service by its "serviceName", but you have to get the name from the service. This means stuff like cred will still work. Of course, similar Services can be written for UNIXListener, SSLListener, etc. -- Moshe Zadka -- http://moshez.org/ Buffy: I don't like you hanging out with someone that... short. Riley: Yeah, a lot of young people nowadays are experimenting with shortness. Agile Programming Language -- http://www.python.org/
On Fri, May 23, 2003 at 07:02:47AM -0000, Moshe Zadka wrote: Subject: Getting rid of Application
I suggest to write ApplicationService classes which look like: class TCPListener(ApplicationService): ... Now, instead of application.listenTCP we can use
TCPListener(8080, server.Site(resource), "foo").setServiceParent(application)
Why do we want to get rid of Application? jml
On Sun, 25 May 2003, jml@mumak.net (Jonathan M. Lange) wrote:
Why do we want to get rid of Application?
Because it's a mess. An Application should be nothing more than a MultiService. Then you can *really* partition your applications however you want to. -- Moshe Zadka -- http://moshez.org/ Buffy: I don't like you hanging out with someone that... short. Riley: Yeah, a lot of young people nowadays are experimenting with shortness. Agile Programming Language -- http://www.python.org/
(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?
participants (3)
-
Glyph Lefkowitz
-
jml@mumak.net
-
Moshe Zadka