On Thu Oct 8 20:08:12 EDT 2009, Glyph Lefkowitz <glyph at
> On Thu, Oct 8, 2009 at 7:59 PM, Mark Visser <markv at lumierevfx.com> wrote:
> > I've been bitten a couple times by twisted's use of old-style classes.
> > Now that Jython is finally off the 2.2 branch, is there any real reason
> > to stay backwards compatible?
> Changing a class from old-style to new-style is an incompatible change. The
> difficulty is that if existing libraries use a particular class and inherit
> from it, changing the class to be new-style can have effects from changing
> how their descriptors work to causing an exception when their module is
> If old-style classes can be evolved into new-style classes while somehow
> following this policy, that would be great. The problem is that providing
> compatibility at this level is time-consuming and difficult. One problem in
> particular is that we don't want to litter the codebase with lots of "Foo"
> and "NewFoo" or "Foo2" sitting right next to it, so we would have to think
> of new names for everything.
I have some POC code for this. It provides a simple toggle at the start
of the application to select between old style (the default) and new style
classes. After that, a DeprecationWarning is issued every time an old
style class is defined. The only user visible change is that old style
classes gain an empty old-style base class. The idea being the
old-style/new-style migration could be managed using the usual twisted
deprecation plan. Thoughts?
Just as the subject says... you guys (everyone involved with TM) are my
I needed to develop a TCP server that could serve multiple GPS tracking
devices over GPRS. These devices uses a multi-level (structures within
structures) style binary protocol. I looked at various possible
solutions which handled the complex asynchronous processing while I
could concentrate on implementing the protocol. Time was of the essence
(as it always is).
I finally ran into Twisted Matrix and it immediately looked very
promising. Only problem was that I didn't know Python at the time and
looking at it for the first time I couldn't make heads or tails out of
it. (I come from a Delphi background but knows a bit of C, PHP and Java
as well). Anyway, after about a week of straining the old brain I not
only managed to learn the basics of Python, but wrote my first concept
server in TM and through it all learned to come to love both of these
solutions very much!
About a month down the line my now completed server is running as smooth
as butter handling an ever growing number of unit's just lovely. The
data, once parsed is all pushed to a Apache/PHP based server via XML-RPC
which in turn performs all the database related stuff. Thanks for all
your hard work guys, it is noticed and deeply, deeply appreciated!
I apologize in advance if this type of request is not desired/allowed
on this list.
I'm looking for a very short-term mentoring/consulting contract to
help me get an Ajax/Comet type of connection working between a web
interface and a fairly long-running, server-side process.
I want the web interface to reflect the server-side data as it
I'm sure someone on this list knows exactly how to hook the pieces
together; I don't.
It would be much more efficient to have someone who already knows
help me hook it up instead of spending an unpredictable amount of time
figuring it out myself.
I'd also like to have, as a primary product of this project, a
tutorial showing a real-world application of Twisted to handle a
modern, real-world use-case with full, open, well documented source
If you're interested, please contact me off-list at
Im playing with a dns-cache script, that overrides DNS requests for certain
I would like to add functionality, so unresolved requests are sent to a
spicific IP. How do I go about doing that?
Is there a negative answer in the (udp) DNS protocol or am I forced to use a
import sys, os
from socket import *
from twisted.internet.protocol import Factory, Protocol
from twisted.internet import reactor
from twisted.names import dns, client, server
LOGFILE = 'dnsfilter.log'
"""file like for writes with auto flush after each write
to ensure that everything is logged, even during an
def __init__(self, f):
self.f = f
def write(self, s):
if __name__ == "__main__":
dns_servers = 
f = open('/etc/resolv.conf', "r")
line = f.readline()
if not line:
s, ns = line.strip().split(' ')
if s == 'nameserver':
#redirect outputs to a logfile
sys.stdout = sys.stderr = Log(open(LOGFILE, 'a+'))
print 'dnsfilter starting'
#address that traffic is redirected to
redirect = '10.0.64.1'
greenlist= ['22.214.171.124', \
def writeMessage(self, message, address):
log = '%s DNS request from: %s\n' % (time.strftime("%m/%d/%y -
%H:%M:%S", time.localtime()) ,address)
for i in range(len(message.answers)):
x = message.answers[i]
if x.type==1 and x.payload:
if not allowip(address):
to_adr = inet_ntoa(x.payload.address)
if to_adr in greenlist:
log += ' allowed to %s\n'%(to_adr)
log += ' not allowed so %s becomes
x.payload.address = inet_aton(redirect)
log += ' to %s\n'%(inet_ntoa(x.payload.address))
resolver = client.Resolver(servers=dns_servers)
f = server.DNSServerFactory(clients=[resolver])
p = DNSDatagramProtocolTest(f)
I'd like to see this ticket get moving again. I've gone over what's been
done so far (and put my comments in the ticket), and it looks like
everything is at least mostly ready to be merged into the Twisted trunk.
So what else needs to be done to get this to happen? I'm happy to try and
get it done, but a little direction would be really handy. ;)
The Gridspy is a commercial product. At the moment we are manufacturing
small runs of prototypes for development and testing, soon they will be
available from our site on-line.
We are making it "hacker friendly" and it has spare serial ports, digital
and analogue inputs so electronics enthusiasts can make their own daughter
boards. We hope it will then become a great way to take your inventions
We consider our "secret sauce" to be the core hardware and the uplink to
the web (including the twisted portion). Everything else on both ends will
be open (still development efforts needed on SDK and documentation). You
will be able to create an electronics gadget that sets the Gridspy / Nexus
analogue and digital inputs and see those inputs changing in some script
you wrote on the web via an RPC mechanism from our server.
Right now our focus is on selling to commercial users here in Auckland, New
Zealand (keep it local) to test the hardware. As production scales up, the
pricing will become much more affordable for us normal people.
Making our platform open and easy to work with is a cause close to my heart
> Message: 3
> Date: Mon, 26 Oct 2009 10:14:30 +0200
> From: Maarten ter Huurne <maarten(a)treewalker.org>
> Subject: Re: [Twisted-Python] Gridspy - a new project using Twisted
> To: Twisted general discussion <twisted-python(a)twistedmatrix.com>
> Message-ID: <200910260914.30601.maarten(a)treewalker.org>
> Content-Type: Text/Plain; charset="iso-8859-15"
> On Monday 26 October 2009, Tom Leys wrote:
>> Gridspy provides you with an interactive view of resource usage in your
>> building. It gives you hard data on your consumption patterns and helps
>> you to make informed decisions.
> How can other people get their own Gridspy? Do you plan to release it as
> do-it-yourself project or as a commercial product?
I am new to twisted and have been having trouble finding out information
about twisted's performance. I have a fairly simple setup where I need to
open a bunch of TCP connections that last for varying amounts of time but
dont do much. I have tried using threads(got GILed to death) and
Processes(even worse). Now I am looking at either making a system to start
the connection and send info to have the remote point "phone home" when its
done, then closing the connection or using something like Twisted.
my socket conversation:
my app -> send a message that triggers an action on the other end
other end -> recv's message does action(can take any amount of time)
other end - > sends results back to my app
Can twisted handle up to several hundred connections like this? Is there a
better approach? Is there anything I should avoid?
how can I chain in defer methods that could raise exception while
showing the exception that coming from method? I mean, if I'll do:
than "Common2AllException" will be raised if abc1() raise Exception,
but I'd like to see the adc1() own exception (and not
t = Test()
if t.test() is None:
if t.test() is None:
if t.test() is None:
Appreciate the help.
>>>>> "vitaly" == vitaly <vitaly(a)synapticvision.com> writes:
vitaly> Thank you a lot for pointing me to the Twisted doc-s, but we're
vitaly> discussing the following snippet:
vitaly> and basically, I've expected in case of exception
vitaly> self.handleFailure1() to be called, but I don't see it happen.
The reason you're not seeing handleFailure1 being called is that the
exception is not occurring in the context of deferred processing. You've
got a regular Python function call, a regular exception is raised, etc.
Twisted and its deferred do not / cannot alter that behavior.
What they *can* do is handle exceptions and turn them into failures and
route the failure to an errback chain *in the context of calling functions
that have been added to a deferred*. Because your abc1 has not been added
to any deferred's call/errback chain, none of that happens when your
exception is raised.
If your code looked like this (pseudocode), you would see the exception
d = defer.Deferred()
def raiser(self, _):
Because the thing that raises is being called by Twisted's deferred class,
and its exception is caught and routed to d's errback chain and winds up in
the handleFailure1 method.
Does that make sense?