source: trunk/misc/operations_helpers/cpu-watcher-subscribe.py

Last change on this file was b856238, checked in by Alexandre Detiste <alexandre.detiste@…>, at 2024-02-15T15:53:34Z

remove old Python2 future statements

  • Property mode set to 100644
File size: 1.4 KB
Line 
1# -*- python -*-
2
3
4from twisted.internet import reactor
5import sys
6
7import os.path, pprint
8from twisted.application import service
9from twisted.python import log
10from foolscap import Tub, Referenceable, RemoteInterface
11from foolscap.schema import ListOf, TupleOf
12from zope.interface import implements
13
14Averages = ListOf( TupleOf(str, float, float, float) )
15class RICPUWatcherSubscriber(RemoteInterface):
16    def averages(averages=Averages):
17        return None
18
19class CPUWatcherSubscriber(service.MultiService, Referenceable):
20    implements(RICPUWatcherSubscriber)
21    def __init__(self, furlthing):
22        service.MultiService.__init__(self)
23        if furlthing.startswith("pb://"):
24            furl = furlthing
25        else:
26            furlfile = os.path.expanduser(furlthing)
27            if os.path.isdir(furlfile):
28                furlfile = os.path.join(furlfile, "watcher.furl")
29            furl = open(furlfile, "r").read().strip()
30        tub = Tub()
31        tub.setServiceParent(self)
32        tub.connectTo(furl, self.connected)
33
34    def connected(self, rref):
35        print("subscribing")
36        d = rref.callRemote("get_averages")
37        d.addCallback(self.remote_averages)
38        d.addErrback(log.err)
39
40        d = rref.callRemote("subscribe", self)
41        d.addErrback(log.err)
42
43    def remote_averages(self, averages):
44        pprint.pprint(averages)
45
46
47c = CPUWatcherSubscriber(sys.argv[1])
48c.startService()
49reactor.run()
50
Note: See TracBrowser for help on using the repository browser.