# HG changeset patch # User Edouard Tisserant # Date 1538488646 -7200 # Node ID 4d7cee25a4743382df4de1d71945a691af40a647 # Parent c44692b5373608b299c082f99f9f206a6d48cf0a# Parent 56f1d8aca88642b2cf62f6a101460e550a3f0faa Merged diff -r 56f1d8aca886 -r 4d7cee25a474 runtime/WampClient.py --- a/runtime/WampClient.py Wed Sep 12 22:59:30 2018 +0200 +++ b/runtime/WampClient.py Tue Oct 02 15:57:26 2018 +0200 @@ -32,13 +32,13 @@ from autobahn.twisted.websocket import WampWebSocketClientFactory, connectWS from autobahn.wamp import types, auth from autobahn.wamp.serializer import MsgPackSerializer -from twisted.internet.defer import inlineCallbacks from twisted.internet.protocol import ReconnectingClientFactory from twisted.python.components import registerAdapter from formless import annotate, webform import formless from nevow import tags, url, static +from runtime import GetPLCObjectSingleton mandatoryConfigItems = ["ID", "active", "realm", "url"] @@ -87,7 +87,7 @@ def GetCallee(name): """ Get Callee or Subscriber corresponding to '.' spearated object path """ names = name.split('.') - obj = _PySrv.plcobj + obj = GetPLCObjectSingleton() while names: obj = getattr(obj, names.pop(0)) return obj @@ -115,7 +115,6 @@ raise Exception( "don't know how to handle authmethod {}".format(challenge.method)) - @inlineCallbacks def onJoin(self, details): global _WampSession _WampSession = self @@ -128,13 +127,13 @@ registerOptions = None print(_("TypeError register option: {}".format(e))) - yield self.register(GetCallee(name), u'.'.join((ID, name)), registerOptions) + self.register(GetCallee(name), u'.'.join((ID, name)), registerOptions) for name in SubscribedEvents: - yield self.subscribe(GetCallee(name), unicode(name)) + self.subscribe(GetCallee(name), unicode(name)) for func in DoOnJoin: - yield func(self) + func(self) print(_('WAMP session joined (%s) by:' % time.ctime()), ID) @@ -145,6 +144,9 @@ _transportFactory = None print(_('WAMP session left')) + def publishWithOwnID(eventID, value): + ID = self.config.extra["ID"] + self.publish(unicode(ID+'.'+eventID), value) class ReconnectingWampWebSocketClientFactory(WampWebSocketClientFactory, ReconnectingClientFactory): @@ -341,6 +343,13 @@ global _PySrv _PySrv = pysrv +def PublishEvent(eventID, value): + if getWampStatus() == "Attached": + _WampSession.publish(eventID, value) + +def PublishEventWithOwnID(eventID, value): + if getWampStatus() == "Attached": + _WampSession.publishWithOwnID(eventID, value) # WEB CONFIGURATION INTERFACE WAMP_SECRET_URL = "secret" diff -r 56f1d8aca886 -r 4d7cee25a474 runtime/Worker.py --- a/runtime/Worker.py Wed Sep 12 22:59:30 2018 +0200 +++ b/runtime/Worker.py Tue Oct 02 15:57:26 2018 +0200 @@ -8,6 +8,7 @@ # See COPYING.Runtime file for copyrights details. from __future__ import absolute_import +import sys import thread from threading import Lock, Condition @@ -54,8 +55,13 @@ """ self._threadID = thread.get_ident() if args or kwargs: - job(*args, **kwargs).do() - # result is ignored + _job = job(*args, **kwargs) + _job.do() + if _job.success: + # result is ignored + pass + else: + raise _job.exc_info[0], _job.exc_info[1], _job.exc_info[2] self.mutex.acquire() while not self._finish: self.todo.wait() diff -r 56f1d8aca886 -r 4d7cee25a474 runtime/__init__.py --- a/runtime/__init__.py Wed Sep 12 22:59:30 2018 +0200 +++ b/runtime/__init__.py Tue Oct 02 15:57:26 2018 +0200 @@ -23,9 +23,8 @@ exp = sys.exc_info() if _PLCObjectSingleton is not None: _PLCObjectSingleton.LogMessage(0, msg + '\n'.join(traceback.format_exception(*exp))) - else: - print(msg) - traceback.print_exception(*exp) + print(msg) + traceback.print_exception(*exp) def CreatePLCObjectSingleton(*args): global _PLCObjectSingleton