XML-RPC performance, RevPi Flat soft watchdog bit

XML-RPC handle multiple request in main loop
XML-RPC log system send max 1M of data
XML-RPC set handler timeout to 2 seconds
Add support for RevPi Flat last bit of RevPiLED word for soft watchdog
This commit is contained in:
2020-10-11 11:35:35 +02:00
parent b24ea9fcb3
commit 7b242865e4
6 changed files with 33 additions and 12 deletions

3
.idea/revpipyload.iml generated
View File

@@ -8,7 +8,4 @@
<orderEntry type="jdk" jdkName="Python 3.6 (revpi)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>

View File

@@ -140,6 +140,9 @@ def get_revpiled_address(configrsc_bytes):
if device.get("type", "") == "BASE":
try:
byte_address = device["offset"] + int(device["out"]["0"][3])
if device.get("productType", "0") == "135":
# On the Flat device the LEDs are 2 Bytes (last Bit is wd)
byte_address += 1
proginit.logger.debug(
"found revpi_led_address on {0} byte".format(byte_address)
)

View File

@@ -18,6 +18,9 @@ class LogReader:
"""
MAX_UPLOAD_SIZE = 1048576
"""Maximum block of logfile."""
def __init__(self):
"""Instantiiert LogReader-Klasse."""
self.fhapp = None
@@ -40,10 +43,17 @@ class LogReader:
@return Binary() der Logdatei
"""
# Max block to prevent freeze
if count > self.MAX_UPLOAD_SIZE:
raise ValueError(
"Parameter count has a max value of {0}"
"".format(self.MAX_UPLOAD_SIZE)
)
if not os.access(proginit.logapp, os.R_OK):
return Binary(b'\x16') # 
return Binary(b'\x16') # ESC
elif start > os.path.getsize(proginit.logapp):
return Binary(b'\x19') # 
return Binary(b'\x19') # EM
else:
with self.fhapplk:
if self.fhapp is None or self.fhapp.closed:
@@ -60,10 +70,17 @@ class LogReader:
@return Binary() der Logdatei
"""
# Max block to prevent freeze
if count > self.MAX_UPLOAD_SIZE:
raise ValueError(
"Parameter count has a max value of {0}"
"".format(self.MAX_UPLOAD_SIZE)
)
if not os.access(proginit.logplc, os.R_OK):
return Binary(b'\x16') # 
return Binary(b'\x16') # ESC
elif start > os.path.getsize(proginit.logplc):
return Binary(b'\x19') # 
return Binary(b'\x19') # EM
else:
with self.fhplclk:
if self.fhplc is None or self.fhplc.closed:

View File

@@ -41,7 +41,7 @@ from json import loads as jloads
from shutil import rmtree
from tempfile import mkstemp
from threading import Event
from time import asctime
from time import asctime, time
from xmlrpc.client import Binary
import logsystem
@@ -876,10 +876,12 @@ class RevPiPyLoad:
self.th_plcslave.start()
if self.xmlrpc and self.xsrv is not None:
# Work xml calls in same thread or wait till timeout
# Work multiple xml calls in same thread until timeout
xml_start = time()
while time() - xml_start < 1.0:
self.xsrv.handle_request()
else:
self.evt_loadconfig.wait(1)
self.evt_loadconfig.wait(1.0)
proginit.logger.info("stopping revpipyload")

View File

@@ -83,6 +83,8 @@ class SaveXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
"""Verwaltet die XML-Requests und prueft Berechtigungen."""
timeout = 2.0
def parse_request(self):
"""Berechtigungen pruefen.
@return True, wenn Parsen erfolgreich war"""

View File

@@ -27,7 +27,7 @@ setup(
license="LGPLv3",
name="revpipyload",
version="0.9.2b",
version="0.9.2c",
scripts=[
"data/revpipyload",