comparison service/piNode/piNode.py @ 639:ad1756af9d99

more piNode wip. treq etc Ignore-this: 153da9ea2f0e0cf56ec2ccb0c5dd5c5
author drewp@bigasterisk.com
date Mon, 12 Aug 2019 10:14:45 -0700
parents 7c04b4f675ec
children 23ab244aa649
comparison
equal deleted inserted replaced
638:6e906d390ed7 639:ad1756af9d99
1 import logging, socket, json, time, pkg_resources 1 import logging, socket, json, time, pkg_resources
2 import cyclone.web 2 import cyclone.web
3 from cyclone.httpclient import fetch
4 from rdflib import Namespace, URIRef, Literal, Graph, RDF, ConjunctiveGraph 3 from rdflib import Namespace, URIRef, Literal, Graph, RDF, ConjunctiveGraph
5 from rdflib.parser import StringInputSource 4 from rdflib.parser import StringInputSource
6 from twisted.internet import reactor 5 from twisted.internet import reactor
7 from twisted.internet.defer import inlineCallbacks, maybeDeferred, returnValue 6 from twisted.internet.defer import inlineCallbacks, maybeDeferred, returnValue
8 from twisted.internet.threads import deferToThread 7 from twisted.internet.threads import deferToThread
46 scales.PmfStat('boardPoll'), 45 scales.PmfStat('boardPoll'),
47 scales.PmfStat('sendOneshot'), 46 scales.PmfStat('sendOneshot'),
48 scales.PmfStat('outputStatements'), 47 scales.PmfStat('outputStatements'),
49 48
50 ) 49 )
51 def patchRandid():
52 """
53 I'm concerned urandom is slow on raspberry pi, and I'm adding to
54 graphs a lot. Unclear what the ordered return values might do to
55 the balancing of the graph.
56 """
57 _id_serial = [1000]
58 def randid():
59 _id_serial[0] += 1
60 return _id_serial[0]
61 import rdflib.plugins.memory
62 rdflib.plugins.memory.randid = randid
63 patchRandid()
64 50
65 class Config(object): 51 class Config(object):
66 def __init__(self, masterGraph, hubHost): 52 def __init__(self, masterGraph, hubHost):
67 self.etcd = etcd3.client(host=hubHost, port=9022) 53 self.etcd = etcd3.client(host=hubHost, port=9022)
68 54
120 self.boards = [] 106 self.boards = []
121 return 107 return
122 108
123 log.info("found config for board %r" % thisBoard) 109 log.info("found config for board %r" % thisBoard)
124 self.boards = [Board(self.configGraph, self.masterGraph, thisBoard, self.hubHost)] 110 self.boards = [Board(self.configGraph, self.masterGraph, thisBoard, self.hubHost)]
125 self.boards[0].startPolling()
126 111
127 112
128 class DeviceRunner(object): 113 class DeviceRunner(object):
129 def __init__(self, dev): 114 def __init__(self, dev):
130 self.dev = dev 115 self.dev = dev