[Twisted-Python] Using SerialPort with t.a.s.Application

Itamar Turner-Trauring itamar at itamarst.org
Fri Jan 28 06:25:52 MST 2011


On Fri, 2011-01-28 at 09:29 +0100, Albert Brandl wrote:
> I'd like to run the application with twistd. But it looks as if SerialPort
> does not really fit into this framework. It does not implement IService,
> so `my_serial_port.setServiceParent(collection)` does not work.

Just implement your own service - subclass t.a.s.Service, write your own
startService and stopService methods that start and stop the serial
port.

> Is there any technical reason that SerialPort does not implement 
> IService?

The TCP port doesn't implement IService either... A service is supposed
to be something you can start and stop, and encapsulates a
self-contained piece of business logic. The purpose is both deployment
and ease of regression testing. So maybe your service starts both a
webserver and a serialport, because it requires both -- which is why
mostly you should just implement your own service classes.

-Itamar





More information about the Twisted-Python mailing list