Re: [Twisted-Python] Twisted meetup/discussion at EuroPython?

2009-04-02 Thread Thomas Hervé
Le mercredi 01 avril 2009 à 13:54 +0200, Terry Jones a écrit :
> I was thinking it would be nice to have a Twisted interest group meetup at
> EuroPython (June 30 - July 2) http://www.europython.eu
> 
> Would people be interested in attending? Does someone more qualified want
> to organize it? Are any Twisted developers planning to be at EuroPython?
> 
> The submissions page http://www.europython.eu/submission/ has a category
> for Interest Group Meeting or Discussion. I'm thinking more along the lines
> of the former - that it would be nice to be better connected to other
> Twisted programmers in Europe, to put a face to some of the names on the
> mailing list / IRC, etc.

I'll probably be there, although I didn't confirm yet. As others, I
won't have the time to organize something too official, but I'll be
happy to join and help.

-- 
Thomas


___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


[Twisted-Python] PBServerFactory - which client disconnected?

2009-04-02 Thread Mike Stoddart
I'm experimenting with Twisted Spread for a registry server, among other
things. I'm just curious how the onDisconnect function knows which client
disconnected? I'm also curious why the PBServerFactory class doesn't have a
disconnection function to complement clientConnectionMade? I don't need
security - this is running on a closed, secure LAN and I don't need
"Avatars". Any suggestions on how to improve this?

from twisted.internet import protocol, reactor
from twisted.python import log
from twisted.spread import pb
import sys

log.startLogging(sys.stdout)


class RegistryService(pb.Root):
def __init__(self):
self._clientCount = 0
self._clients = {}

def remote_register(self, name, service):
log.msg("Registering service " + name)
log.msg(str(service))

# Welcome the client.
service.callRemote("welcome")

def onDisconnect(self):
log.msg("onDisconnect")

log.msg("Client count = " + str(len(self._clients)))

def onConnect(self, broker):
s = broker.transport.getPeer().host + ":" +
str(broker.transport.getPeer().port)
log.msg("onConnect - client at " + s)

# Add the client.
self._clients[s] = broker.transport
log.msg("Client count = " + str(len(self._clients)))

# Set a callback in case they disconnect.
broker.notifyOnDisconnect(self.onDisconnect)

class MyPBFactory(pb.PBServerFactory):
def __init__(self, root):
pb.PBServerFactory.__init__(self, root)

def clientConnectionMade(self, broker):
log.msg("clientConnectionMade")
self.root.onConnect(broker)

registry = RegistryService()
f = MyPBFactory(RegistryService())
reactor.listenTCP(, f)
reactor.run()


Thanks
Mike
___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] Twistd and application framework questions

2009-04-02 Thread Itamar Shtull-Trauring
On Wed, 2009-04-01 at 13:16 -0400, Nadav Aharony wrote:

> 1) The program uses multiple UDP/TCP clients and servers that are 
> currently launched with reactor.listenTCP / UDP connectTCP/UDP etc. I've 
> been using MultiService, according to the twisted documentation.
> Some of these services were are at a top level of my app so it was easy 
> to turn that part into a .tac file and switch the reacor calls to 
> internet.TCPServer etc.
> However, some of them are deep inside my code, and are instantiated on 
> the fly.
> 
> What is the "right" way to attach them to my service parent? (the part 
> with ".setServiceParent(")
> Should I now add a pointer to my MultiService that will be propagated 
> down the  code hierarchy to each of these calls and be accessible at the 
> inner scopes?
> Is there a neater way to do it just with importing the right modules? 
> (in the same way that in usual twisted scripts the loaded reactor is a 
> global reactor)
> 
> 2)  There are still scenarios where I would want to run my code the 
> "reactor" way rather than than using the application framework, and I 
> would love to be able to keep a single file that's compatible with both 
> modes..
> Is there a way to detect in runtime whether the code is being run 
> through 'twistd' and the app framework or if its run directly?
> I was thinking of doing something like:
> 
> if :
> internet.TCPServer(,).setServiceParent()
> else:

1. You don't need to attach to parents service, you can also call
start/stopService directly.

2. You can still call "self.port = reactor.listenTCP(...)" directly in a
custom startService, and self.port.stopListening() in a custom
stopService. You don't have to use twisted.application.internet, it
doesn't add much beyond a little convenience.

The point of services is to encapsulate startup and shutdown logic, not
to make your life harder :)


___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] official packaging

2009-04-02 Thread David Ripton
On 2009.04.02 14:21:14 +1100, Tim Allen wrote:
> Esteve Fernandez  wrote:
> > Anyway, it would be great to have recent packages of Twisted for 
> > distributions 
> > that offer some kind of long term support contracts (Ubuntu, RHEL, etc.), 
> > but 
> > that tend to get a bit outdated.
> 
> It's worth mentioning that someone has recently stepped up to fix
> ticket 1696 after I'd ignored it for Far Too Long, and very soon it
> should be possible to build Twisted RPMs for RHEL just by running
> "./setup.py bdist_rpm" in a fresh checkout.

Thanks Tim.  I make RHEL5 rpms for Twisted at work, using "setup.py
bdist_rpm" rather than a manually generated spec file.  I thought we
were just about the only ones who cared about this, so I've never really
tried to push the (small) changes upstream.  But when your changes land
I'll test that they work for us too.

An issue with pushing this kind of change to RPM-based distros is that
writing .spec files by hand and maintaining them is their core
competency, so they mostly think using setup.py bdist_rpm to
autogenerate them is weird and unnecessary and wrong.

-- 
David Riptondrip...@ripton.net

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


[Twisted-Python] Documentation overviews

2009-04-02 Thread Cary Hull
Hi folks,

One of the goals for the Pycon sprint was to develop user oriented overviews
for existing documentation.
These would ideally guide users through everything they would need to read
in order to accomplish a desired goal with Twisted.

I've formulated the following 'track' suggestions based on a conversation in
the sprint room a few nights ago.
Feedback would be greatly appreciated.

---

Overviews

#   The basics of event driven applications (beginner)

#   No hand holding, just the facts (advanced, already familiar with
concepts involved)

#   Testing Twisted applications

#   Driving processes (interactively or otherwise)

#   Custom protocols

#   When it makes sense to use threads

#   Persisting application data (Would cover various options including
Axiom)

#   Task scheduling (Would cover various options including Axiom)

#   Web clients

#   Web applications using just Twisted

#   Web applications using WSGI (Maybe show how to run Django)

#   Mail clients

#   Mail servers

#   SSH clients

#   SSH servers

#   XMPP (Jabber) clients

#   XMPP (Jabber) servers

#   Multiple servers in a single application

#   GUI applications (non web)

#   Networked video games
___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] Documentation overviews

2009-04-02 Thread Michael P. Soulier
On 02/04/09 Cary Hull said:

> #   Web clients
> 
> #   Web applications using just Twisted
> 
> #   Web applications using WSGI (Maybe show how to run Django)

# Web proxies, with and without authentication, with and without SSL

Mike
-- 
Michael P. Soulier 
"Any intelligent fool can make things bigger and more complex... It takes a
touch of genius - and a lot of courage to move in the opposite direction."
--Albert Einstein


pgpgd8B0kuHUT.pgp
Description: PGP signature
___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] Twistd and application framework questions

2009-04-02 Thread Terry Jones
Hi Nadav, Itamar

> "Itamar" == Itamar Shtull-Trauring  writes:
Itamar> On Wed, 2009-04-01 at 13:16 -0400, Nadav Aharony wrote:

>> 1) The program uses multiple UDP/TCP clients and servers that are
>> currently launched with reactor.listenTCP / UDP connectTCP/UDP etc. I've
>> been using MultiService, according to the twisted documentation.  Some
>> of these services were are at a top level of my app so it was easy to
>> turn that part into a .tac file and switch the reacor calls to
>> internet.TCPServer etc.  However, some of them are deep inside my code,
>> and are instantiated on the fly.

We (at Fluidinfo) have a similar situation, though I wouldn't say the
services that start/stop later are deeply buried. They're just not started
right away when startService is called on the MultiService via the plugin
mechanism.

>> What is the "right" way to attach them to my service parent? (the part
>> with ".setServiceParent(") Should I now add a pointer to
>> my MultiService that will be propagated down the code hierarchy to each
>> of these calls and be accessible at the inner scopes?  Is there a neater
>> way to do it just with importing the right modules?  (in the same way
>> that in usual twisted scripts the loaded reactor is a global reactor)

At the suggestion/insistence :-) of Esteve Fernandez, we do this by using
the components machinery of Twisted. You write an adaptor that knows how to
take the core of your service and adapt it to some other form of service
interface. The adaptor can have access to the original Multiservice, it can
provide startService and stopService methods that call into the special
service that you're trying to launch, etc.  It's nice because the
mechanisms for creating a new service and getting it hooked up to the
outside world, can be encapsulated in the adaptor and don't pollute the
code that's trying to just provide the underlying service (your "business
logic" I guess you'd call that :-))

BTW, we also have some service startup ordering constraints that we fixed
by subclassing Multiservice. There's a slow-motion thread on this approach,
so the jury's still out, but the code described here works fine for me:

  http://twistedmatrix.com/pipermail/twisted-python/2009-February/019225.html
  http://twistedmatrix.com/pipermail/twisted-python/2009-February/019249.html

Itamar> 1. You don't need to attach to parents service, you can also call
Itamar> start/stopService directly.

Itamar> 2. You can still call "self.port = reactor.listenTCP(...)" directly
Itamar> in a custom startService, and self.port.stopListening() in a custom
Itamar> stopService. You don't have to use twisted.application.internet, it
Itamar> doesn't add much beyond a little convenience.

Itamar> The point of services is to encapsulate startup and shutdown logic,
Itamar> not to make your life harder :)

The main reason I like to add the new service to the original Multiservice
is that its stopService gets called at the right time and I don't have to
think about it. That's a nice convenience.

Terry

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


[Twisted-Python] Re: PBServerFactory - which client disconnected?

2009-04-02 Thread Mike Stoddart
So I can do the following but the onDisconnect and onConnect functions don't
receive the broker - odd design decision?
Also, there's a comment in PBServerFactory.clientConnectionMade --> "# XXX
does this method make any sense?".  Weird.

class MyServerObject(pb.Root):
def __init__(self):
pass

def onConnect(self):
log.msg("MyServerObject::onConnect")

def onDisconnect(self):
log.msg("MyServerObject::onDisconnect")

class MyServerFactory(pb.PBServerFactory):

def buildProtocol(self, addr):
s = addr.host + ":" + str(addr.port)
log.msg("MyServerFactory::buildProtocol - building protocol for " +
s)
broker = pb.PBServerFactory.buildProtocol(self, addr)
broker.notifyOnDisconnect(self.root.onDisconnect)
broker.notifyOnConnect(self.root.onConnect)
return broker

reactor.listenTCP(, MyServerFactory(MyServerObject()))
reactor.run()

On Thu, Apr 2, 2009 at 8:02 AM, Mike Stoddart  wrote:

> I'm experimenting with Twisted Spread for a registry server, among other
> things. I'm just curious how the onDisconnect function knows which client
> disconnected? I'm also curious why the PBServerFactory class doesn't have a
> disconnection function to complement clientConnectionMade? I don't need
> security - this is running on a closed, secure LAN and I don't need
> "Avatars". Any suggestions on how to improve this?
>
> from twisted.internet import protocol, reactor
> from twisted.python import log
> from twisted.spread import pb
> import sys
>
> log.startLogging(sys.stdout)
>
>
> class RegistryService(pb.Root):
> def __init__(self):
> self._clientCount = 0
> self._clients = {}
>
> def remote_register(self, name, service):
> log.msg("Registering service " + name)
> log.msg(str(service))
>
> # Welcome the client.
> service.callRemote("welcome")
>
> def onDisconnect(self):
> log.msg("onDisconnect")
>
> log.msg("Client count = " + str(len(self._clients)))
>
> def onConnect(self, broker):
> s = broker.transport.getPeer().host + ":" +
> str(broker.transport.getPeer().port)
> log.msg("onConnect - client at " + s)
>
> # Add the client.
> self._clients[s] = broker.transport
> log.msg("Client count = " + str(len(self._clients)))
>
> # Set a callback in case they disconnect.
> broker.notifyOnDisconnect(self.onDisconnect)
>
> class MyPBFactory(pb.PBServerFactory):
> def __init__(self, root):
> pb.PBServerFactory.__init__(self, root)
>
> def clientConnectionMade(self, broker):
> log.msg("clientConnectionMade")
> self.root.onConnect(broker)
>
> registry = RegistryService()
> f = MyPBFactory(RegistryService())
> reactor.listenTCP(, f)
> reactor.run()
>
>
> Thanks
> Mike
>
___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


[Twisted-Python] Question about application exit handling

2009-04-02 Thread Jay Deiman
First, I'm pretty new to the Twisted framework and I've spent a lot of 
time poking through documentation and subsequently, I've managed to 
figure out a lot of things on my own.


Here is one issue I'm having right now.  I wrote an application to be 
run under twistd and it works great, except for one problem.  When I try 
to exit twistd, it hangs.  I know why this is, it's due to a 
twisted.python.threadpool.ThreadPool that I've instantiated and use in 
my code.  Now, here is the actual question.  Is there a 
callback/signal/notifier of some sort that is triggered when an 
application is closed?  I know twistd handles the SIGINT, SIGTERM, etc., 
but is there some sort of notification that is sent to the current 
running application that I can use for clean up?


Thanks,

Jay

--
Jay Deiman

\033:wq!

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] Question about application exit handling

2009-04-02 Thread Jay Deiman

Jay Deiman wrote:
First, I'm pretty new to the Twisted framework and I've spent a lot of 
time poking through documentation and subsequently, I've managed to 
figure out a lot of things on my own.


Here is one issue I'm having right now.  I wrote an application to be 
run under twistd and it works great, except for one problem.  When I try 
to exit twistd, it hangs.  I know why this is, it's due to a 
twisted.python.threadpool.ThreadPool that I've instantiated and use in 
my code.  Now, here is the actual question.  Is there a 
callback/signal/notifier of some sort that is triggered when an 
application is closed?  I know twistd handles the SIGINT, SIGTERM, etc., 
but is there some sort of notification that is sent to the current 
running application that I can use for clean up?


Nevermind.  I initially misunderstood the startFactory() and 
stopFactory() method docs for the Factory class.  Everything works 
perfectly now.


--
Jay Deiman

\033:wq!

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


[Twisted-Python] PBClientFactory and getRootObject

2009-04-02 Thread Fabrizio Mancini
Hi everyone,
I'm writing a server and a client using Perspective Broker with no Avatar
and no auth.
The server accumulates some data using a DeferredQueue.
The clients using a remote call retrieve one item per time from the queue
and elaborates it making some changes on a database using adbapi.
What i want to know is:
1) how can i recursively call the remote method to retrieve the items from
the server?
2) can i defer the database operations to a thread so every client can
elaborates multiple requests per time?

The code i'm using is this:

from twisted.internet import reactor, defer, pb
from twisted.enterprise import adbapi
from twisted.python import log
import os

globalConfigurationFile=os.path.abspath('conf' + os.sep +
'configuration.ini')

class DataBasePreparerClient(object):
'''
DataBasePreparerClient()
'''

def __init__(self, globalConfigurationFile):
self._gcf = globalConfigurationFile
self.data = {}
self._parseConfig()
self._createDbPool()
self.d = defer.Deferred()
self.clientfactory = pb.PBClientFactory()

def _createDbPool(self):
self.dbpool = adbapi.ConnectionPool('cx_Oracle',
self.data['db_username'], self.data['db_password'], self.data['db_tns'])

def connect(self):
reactor.connectTCP(self.data['server_ip'], self.data['server_port'],
self.clientfactory)
self.d = self.clientfactory.getRootObject()
self.dbpool.connect()
self.d.addCallbacks(self.get_item, self._eb)

def _eb(self, reason):
print "Failure: ", reason.getErrorMessage()

def get_item(self, result):
d = result.callRemote("get_item")
d.addCallback(self.got_item)

def got_item(self, item):
query = "update table where ..."
res = self.dbpool.runOperation(query)
res.addErrback(self._eb)
self.d = self.clientfactory.getRootObject()
self.d.addCallbacks(self.get_item, self._eb)

if __name__ == "__main__":
DataBasePreparerClient(globalConfigurationFile).connect()
reactor.run()

To call recursively the remote object in function connect i call
clientfactory.getRootObject() and addCallback() for the first time, and the
i recall always self.clientfactory.getRootObject() and self.d.addCallback
when the db query has completed.
Is this correct?
Do I have to always call self.clientfactory.getRootObject() every time i
have to call a remote method?
Can i deferToThread the function got_item or
self.dbpool.runOperation(query)?
Thanks in advance
Fabrizio
___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python