Exemplo n.º 1
0
def initialize():
    global vtkpython
    global weblauncher

    # Get the module config.
    config = tangelo.plugin_config()

    # Raise an error if there's no vtkpython executable.
    vtkpython = config.get("vtkpython", None)
    if not vtkpython:
        msg = "No 'vtkpython' option specified in configuration plugin"
        tangelo.log_warning("VTKWEB", "[initialization] fatal error: %s" % (msg))

        # Construct a run() function that will mask the restful API and just
        # inform the caller about the configuration problem.
        def run():
            tangelo.http_status(400, "Bad Configuration")
            return {"error": msg}

        sys.modules[__name__].__dict__["run"] = run
        return

    vtkpython = tangelo.util.expandpath(vtkpython)
    tangelo.log("VTKWEB", "[initialization] Using vtkpython executable %s" % (vtkpython))

    # Use the "web launcher" included with the plugin.
    weblauncher = os.path.realpath("%s/../include/vtkweb-launcher.py" % (os.path.dirname(__file__)))

    # Initialize a table of VTKWeb processes.
    if tangelo.plugin_store().get("processes") is None:
        tangelo.plugin_store()["processes"] = {}

    # Check to see if a reactor is running already.
    if twisted.internet.reactor.running:
        threads = [t for t in threading.enumerate() if t.name == "tangelo-vtkweb-plugin"]
        if len(threads) > 0:
            tangelo.log_warning(
                "VTKWEB", "[initialization] A reactor started by a previous loading of this plugin is already running"
            )
        else:
            tangelo.log_warning(
                "VTKWEB", "[initialization] A reactor started by someone other than this plugin is already running"
            )
    else:
        # Start the Twisted reactor, but in a separate thread so it doesn't
        # block the CherryPy main loop.  Mark the thread as "daemon" so that
        # when Tangelo's main thread exits, the reactor thread will be killed
        # immediately.
        reactor = threading.Thread(
            target=twisted.internet.reactor.run, kwargs={"installSignalHandlers": False}, name="tangelo-vtkweb-plugin"
        )
        reactor.daemon = True
        reactor.start()

        tangelo.log_info("VTKWEB", "[initialization] Starting Twisted reactor")
Exemplo n.º 2
0
def initialize():
    global vtkpython
    global weblauncher

    # Get the module config.
    config = tangelo.plugin_config()

    # Raise an error if there's no vtkpython executable.
    vtkpython = config.get("vtkpython", None)
    if not vtkpython:
        msg = "No 'vtkpython' option specified in configuration plugin"
        tangelo.log_warning("VTKWEB", "[initialization] fatal error: %s" % (msg))

        # Construct a run() function that will mask the restful API and just
        # inform the caller about the configuration problem.
        def run():
            tangelo.http_status(400, "Bad Configuration")
            return {"error": msg}

        sys.modules[__name__].__dict__["run"] = run
        return

    vtkpython = tangelo.util.expandpath(vtkpython)
    tangelo.log("VTKWEB", "[initialization] Using vtkpython executable %s" % (vtkpython))

    # Use the "web launcher" included with the plugin.
    weblauncher = os.path.realpath("%s/../include/vtkweb-launcher.py" % (os.path.dirname(__file__)))

    # Initialize a table of VTKWeb processes.
    if tangelo.plugin_store().get("processes") is None:
        tangelo.plugin_store()["processes"] = {}

    # Check to see if a reactor is running already.
    if twisted.internet.reactor.running:
        threads = [t for t in threading.enumerate() if t.name == "tangelo-vtkweb-plugin"]
        if len(threads) > 0:
            tangelo.log_warning("VTKWEB", "[initialization] A reactor started by a previous loading of this plugin is already running")
        else:
            tangelo.log_warning("VTKWEB", "[initialization] A reactor started by someone other than this plugin is already running")
    else:
        # Start the Twisted reactor, but in a separate thread so it doesn't
        # block the CherryPy main loop.  Mark the thread as "daemon" so that
        # when Tangelo's main thread exits, the reactor thread will be killed
        # immediately.
        reactor = threading.Thread(
            target=twisted.internet.reactor.run,
            kwargs={"installSignalHandlers": False},
            name="tangelo-vtkweb-plugin"
        )
        reactor.daemon = True
        reactor.start()

        tangelo.log_info("VTKWEB", "[initialization] Starting Twisted reactor")
Exemplo n.º 3
0
def install():
    """Install and reset the test reactor"""
    if not isinstance(reactor,TestReactor):
        assert reactor.__class__ is selectreactor.SelectReactor, (
            "testreactor can only be installed over the default reactor"
        )
        reactor.__class__ = TestReactor

    reactor.start()

    # If Twisted defined these as methods on reactors, we wouldn't
    # need to monkeypatch their globals like this.  :(
    task.Clock.seconds = lambda c: reactor.seconds
    selectreactor.sleep = reactor.sleep
    selectreactor._select = reactor.select
Exemplo n.º 4
0
 def testReactorResetsScheduledCalls(self):
     reactor.callLater(5, reactor.crash)
     reactor.waitFor(3)
     reactor.start()  # reset reactor completely
     reactor.waitFor(10, False)  # this should fail if callback is active
Exemplo n.º 5
0
 def testReactorResetsScheduledCalls(self):
     reactor.callLater(5, reactor.crash)
     reactor.waitFor(3)
     reactor.start()     # reset reactor completely
     reactor.waitFor(10, False)  # this should fail if callback is active
 def connectionMade(self):
     print "Connection Made"
     reactor.start()
 def clientConnectionFailed(self, connector, reason):
     print "Connection faled becase", reason
     reactor.start()