[Twisted-Python] DirtyReactorAggregateError: Reactor was unclean. - What to do?

2013-11-13 Thread Jonas Brunsgaard
Dear list

I may need som advise to get som testing wokring.

I have a server for service a, which creates a client for service b to get
som data:

 class StateHandler(object):
implements(State.Iface)

def __init__(self):
#do stuff
self.loaddata()

 @inlineCallbacks
def loaddata(self):
try:
conn = yield ClientCreator(
reactor,
TTwisted.ThriftClientProtocol,
dsClient,

TBinaryProtocol.TBinaryProtocolFactory()).connectTCP("10.70.10.30", 7246)
data = yield conn.client.getAllAuthenticationData()
#process data
conn.transport.loseConnection()

I use trail to test this service, code is bolow:

class TestStateStore(unittest.TestCase):

 @defer.inlineCallbacks
def setUp(self):
self.handler = StateHandler()
self.processor = State.Processor(self.handler)
self.pfactory = TBinaryProtocol.TBinaryProtocolFactory()
self.server = reactor.listenTCP(
0,
TTwisted.ThriftServerFactory(self.processor, self.pfactory),
interface="127.0.0.1")
self.portNo = self.server.getHost().port
self.txclient = yield ClientCreator(
reactor,
 TTwisted.ThriftClientProtocol,
State.Client,
self.pfactory).connectTCP("127.0.0.1", self.portNo)
self.client = self.txclient.client

@defer.inlineCallbacks
def tearDown(self):
self.txclient.transport.loseConnection()
yield self.server.stopListening()


def test_dummy(self):
self.assertEquals(True, True)

When I run test it fails with the following error message.

ERROR]
Traceback (most recent call last):
Failure: twisted.trial.util.DirtyReactorAggregateError: Reactor was unclean.
DelayedCalls: (set twisted.internet.base.DelayedCall.debug = True to debug)


oc.tests.test_state_service.TestStateStore.test_dummy
===
[ERROR]
Traceback (most recent call last):
Failure: twisted.trial.util.DirtyReactorAggregateError: Reactor was unclean.
Selectables:
< to ('10.70.10.30', 7246) at 29d2c10>

oc.tests.test_state_service.TestStateStore.test_dummy
---
Ran 1 tests in 0.010s

To me it seems like Trail shuts down the reactor and throws an error, due
to the fact that the reactor is unclean, because the server client is still
active, or at least not cleaned up. How do I work around this problem, any
help is very appreciated.

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


Re: [Twisted-Python] Is a Viewable Cacheable a good idea?

2013-11-13 Thread Flint
Hi,

>> Is simultaneously sub-classing Viewable and Cacheable a good idea?
I am not sure it would work, at least not as you expect.
Viewable and Cacheable both implement a different version of jellyFor
(which will decides how object is seen on the other side of the connection).
If you sub-class both of them your resulting class will act either as a
cacheable or as a viewable depending on how you sub-class them -- at least
for the serialization part.

For your problem, It seems to me that you're trying to do 2 things:
1 - manage a server side object of stockroom(s)
2 - keep a copy of that object(s) synchronized in clients.

So may be (IMHO) you could have one viewable object acting like a
stockroom-manager that clients will (remote)call to make changes on the
server side stockroom-object,
And a cacheable stockroom-object, that you will sync with client.

That said, note that, there is no magic in the sync process when using
cacheable, you will have to propagate the change made to the cacheable
object yourself, by implementing the observe_ methods.
And when you make any changes to the server copy you will have to call
those observe_ methods on all clients, just as you said you would do in
your example.

Another option would be to stockroom object with copyable items and
implement getter method in the stockroom-manager, so clients would be able
to query only data that they need, when they need it, and then do not fire
all the sync stuff each time your stockroom is updates.
Besides cacheable object are said to be used for big object that do not
change frequently, which is not the case of your stockroom I guess.

Hope this help.
--
Nacim.






2013/11/12 Daniel Sank 

> Suppose I want to make a networked stockroom program with perspective
> broker. We have a user side client object,
>
> class Client(pb.Referenceable):
> def connect(self):
> # host, port, factory, and credentials come from elsewhere
> reactor.connectTCP(host, port, factory)
> d = self.factory.login(credentials, self)
> d.addCallback(self.connected)
>
> def connected(self, perspective):
> if perspective:
> self.perspective = perspective
>
> and a "corresponding" server side User,
>
> class User(pb.Avatar):
> def __init__(self, name, server, mind):
> self.name = name
> self.server = server
> self.client = mind #This is a remote reference to a Client
>
> def logout(self):
> ...logic...
>
> We have the IRealm implementer,
>
> @implementer(portal.IRealm)
> class Server(object):
> """I manage games and produce Avatars"""
> def __init__(self, loggingPath):
> self.users = {}
> self.stockrooms = set()
>
> def requestAvatar(self, avatarId, mind, *interfaces):
> assert pb.IPerspective in interfaces
> user = self.users.setdefault(avatarId, User(avatarId, self, mind))
> return pb.IPerspective, user, user.logout
>
> and finally we have the Stockroom
>
> class Stockroom(object):
> ...logic...
>
> Now I'd like for my Clients to be able to remove/add items to the
> stockroom. Using only the code above I'd have to add perspective_*
> methods to the User. These methods would direct the Client's intent to
> the appropriate Stockroom. Changes made to the Stockroom would then
> have to be announced to any interested Clients by invoking the
> appropriate Users' mind property.
>
> This seems very awkward. I'd rather just have the Stockrooms be
> Viewable so that Clients can invoke methods on them directly. If the
> Stockroom were _also_ Cacheable then changes on a Stockroom would
> automatically propagate to the client process.
>
> Is simultaneously sub-classing Viewable and Cacheable a good idea?
>
> Am I thinking about this properly?
>
> Regards and thanks in advance,
> Daniel Sank
>
> --
> Department of Physics
> Broida Hall
> University of California
> Santa Barbara, CA 93117
> (805)893-3899
>
> ___
> Twisted-Python mailing list
> Twisted-Python@twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python