runtime/__init__.py
author Edouard Tisserant
Tue, 21 Aug 2018 16:11:02 +0200
changeset 2270 d9175daf6522
parent 1984 081265cda5b1
child 2307 c44692b53736
permissions -rw-r--r--
Refactoring. Separated PLC Object, PYRO Server and MainWorker :
- PLC Object is now a Singleton, instantiated through runtime.CreatePLCObjectSingleton(...)
- Pyro server doesn't hold any reference to PLCObject, and doesn't create it anymore
- PLC Object class doesn't inherit from Pyro.ObjBase anymore
- Pyro related code moved to runtime.PyroServer.py
- MainWorker class moved to runtime/Worker.py
- Both PLC Object and MainWorker creation happens in runtime/__init__.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import
import traceback

from runtime.Worker import worker
MainWorker = worker()

from runtime.PLCObject import PLCObject

_PLCObjectSingleton = None

def GetPLCObjectSingleton():
    global _PLCObjectSingleton
    assert(_PLCObjectSingleton is not None)
    return _PLCObjectSingleton


def LogMessageAndException(msg, exp=None):
    global _PLCObjectSingleton
    if exp is None:
        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)

def CreatePLCObjectSingleton(*args):
    global _PLCObjectSingleton
    _PLCObjectSingleton = PLCObject(*args)