[Twisted-Python] Is it just me ....

Moshe Zadka m at moshez.org
Thu Jul 10 06:41:25 MDT 2003


On Thu, 10 Jul 2003, Neil Blakey-Milner <nbm at mithrandr.moria.org> wrote:

> Bannergrab is at http://mithrandr.moria.org/code/bannergrab/ and it is
> a simple SSH/SMTP banner grabber over a (bunch of) network range(s).
> Not much I'd like done with it, but suggestions on what is good/bad
> about it would be nice.  Also, a "so many concurrent clients" manager
> like I used might be useful in general - what do others think?

It's not that dissimilar with some code we have in mail. Unfortunately,
a bunch of that code is not that great an example code either.

You probably don't want to call reactor.stop(). Ever.
What you want is for Manager to create a deferred which is callbacked
when there are no more slaves or waiting slaves, and let someone
else call reactor.stop() if he should wish it. I'm not exactly sure
if this is the right way, of if it should be converted to an
ApplicationService -- that depends on what you want to do.

For example, I could see an excellent case for just removing the prints
in favour of saving the data and then callback'ing the deferred, and
wrapping it all in a nice function, which can be called like this:

checkHosts(('moshez.org', 25), ('moshez.org', 22)
).addCallback(util.println
).addCallback(lambda _: reactor.stop())

One nit: protocol.slashr means you are changing a class attribute.
That's probably a bad idea. It would be better to inherit:

class UnixMyProtocol(MyProtocol):
    delimiter = '\n'

and do
  if not slashr:
      slave.protocol = UnixMyProtocol
in the relevant places.
-- 
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/




More information about the Twisted-Python mailing list