[Twisted-Python] serial port blocking on Linux

Eric C. Newton ecn at metaslash.com
Tue Apr 22 19:39:38 EDT 2003

Twisted 1.0.4
Linux Redhat 9.0

I have evidence of the SerialPort class blocking.  

strace says write operations are blocking and always return the number
of bytes to be written.

The problem goes away if I set the file descriptor on the object to
non-blocking using posixy controls.

Test program below.


#! /usr/bin/python
from twisted.internet import reactor
from twisted.internet.serialport import SerialPort
from twisted.protocols.basic import LineReceiver
import fcntl, os

import time

class Client(LineReceiver):
    def connectionMade(self):
        # Uncomment to fix
        #assert fcntl.fcntl(self.transport.fileno(),
        #                   fcntl.F_SETFL,
        #                   os.O_RDWR|os.O_NONBLOCK) == 0
        before = time.time()
        self.transport.write('This is a long message\n' * 500)
        after = time.time()
        print 'long write took', after - before, 'seconds'

    def lineReceived(self, line):
s = SerialPort(Client(), '/dev/ttyS1', reactor)

More information about the Twisted-Python mailing list