Skip to content

Instantly share code, notes, and snippets.

@meejah meejah/
Created Apr 3, 2014

What would you like to do?
"tail -f" style file-reading in Twisted
#!/usr/bin/env python
import sys
from twisted.internet.interfaces import IReadDescriptor
from twisted.internet.fdesc import setNonBlocking
from twisted.internet import reactor
from zope.interface import implementer
class Blam(object):
def __init__(self, f):
self.file = f
def logPrefix(self):
return 'blam'
def doRead(self):
data =
if data:
print "it's dataz", data
def fileno(self):
return self.file.fileno()
def connectionLost(self, why):
print "closed", why
f = Blam(open(sys.argv[1], 'r'))
print "go!", sys.argv[1]

This comment has been minimized.

Copy link

kneufeld commented Apr 3, 2014

does not notice new lines on OSX
uses 100% cpu


This comment has been minimized.

Copy link
Owner Author

meejah commented Apr 3, 2014

Hmm, it seems to be using 100% CPU on Debian, also -- clearly something is missing...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.