~landscape/twisted/14.0.2-1ubuntu1

« back to all changes in this revision

Viewing changes to doc/core/howto/listings/pb/cache_receiver.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-07-14 13:53:15 UTC
  • mfrom: (1.3.2) (44.2.3 sid)
  • Revision ID: package-import@ubuntu.com-20140714135315-z2f6727ypy31nldq
Tags: 14.0.0-1ubuntu1
* Merge with Debian; remaining changes:
  - Keep the preliminary python3 support, but don't enable it.
  - Try to use plain pygtkcompat and fall back to gi.pygtkcompat, to
    avoid a DeprecationWarning, and a crash.
  - Use new io_add_watch api on new versions of pygobject.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
 
3
 
# Copyright (c) Twisted Matrix Laboratories.
4
 
# See LICENSE for details.
5
 
 
6
 
from twisted.application import service, internet
7
 
from twisted.internet import reactor
8
 
from twisted.spread import pb
9
 
import cache_classes
10
 
 
11
 
class Receiver(pb.Root):
12
 
    def remote_takePond(self, pond):
13
 
        self.pond = pond
14
 
        print "got pond:", pond # a DuckPondCache
15
 
        self.remote_checkDucks()
16
 
    def remote_checkDucks(self):
17
 
        print "[%d] ducks: " % self.pond.count(), self.pond.getDucks()
18
 
    def remote_ignorePond(self):
19
 
        # stop watching the pond
20
 
        print "dropping pond"
21
 
        # gc causes __del__ causes 'decache' msg causes stoppedObserving
22
 
        self.pond = None
23
 
    def remote_shutdown(self):
24
 
        reactor.stop()
25
 
 
26
 
application = service.Application("copy_receiver")
27
 
internet.TCPServer(8800, pb.PBServerFactory(Receiver())).setServiceParent(
28
 
    service.IServiceCollection(application))