Beispiel #1
0
def runner(cls):

    # Run with a fresh server
    server = app.create_server(port=0, new_loop=True)

    t = app.launch(cls, 'firefox-app')
    t.test_init()
    t.test_set_result()
    # Install failsafe. Use a closure so failsafe wont spoil a future test
    isrunning = True

    def stop():
        if isrunning:
            app.stop()

    app.call_later(TIMEOUT1, stop)
    # Enter main loop until we get out
    t0 = time.time()
    app.start()
    print('ran %f seconds' % (time.time() - t0))
    isrunning = False
    # Check result
    if True:  # not (ON_TRAVIS and ON_PYPY):  # has intermittent fails on pypy3
        t.test_check()
    # Shut down
    t.session.close()
Beispiel #2
0
 def inner(simulation):
     database = dataset.connect('sqlite:///parameter.db')
     abcEconomics.parameter_database = database['parameter']
     Form = form(parameter_mask, names)  # pylint: disable=C0103
     if serve:
         flexx.config.hostname = hostname
         flexx.config.port = port
         app.serve(
             basiclayout(Form,
                         simulation,
                         title,
                         header,
                         truncate_rounds,
                         texts=texts,
                         pages=pages,
                         histograms=histograms))
         app.start()
     else:
         app.launch(basiclayout(Form,
                                simulation,
                                title,
                                header,
                                truncate_rounds,
                                texts=texts,
                                pages=pages,
                                histograms=histograms),
                    windowmode='maximized',
                    runtime=runtime)
         app.run()
     return lambda _: None
Beispiel #3
0
 def try_start():
     try:
         app.stop()
         app.start()
     except RuntimeError:
         res.append('start-fail')
     else:
         res.append('start-ok')
Beispiel #4
0
 def try_start():
     try:
         app.stop()
         app.start()
     except RuntimeError:
         res.append('start-fail')
     else:
         res.append('start-ok')
Beispiel #5
0
def test_serving_apps_at_output_message():
    """ Test for 'Serving apps at' ready signal.
    """
    with capture_log('info') as log:
        server = app.create_server()
        app.stop()  # triggers event to stop
        app.start()

    assert 'Serving apps at' in ''.join(log)
Beispiel #6
0
def main():
    if len(sys.argv) > 1:
        app.export(BeetMe, "beetme.html", link=0)
    else:
        app.serve(BeetMe)
        tornado_app = app.current_server().app
        tornado_app.add_handlers(r".*", [
            (r"/beet.*", BeetHandler),
        ])
        app.start()
Beispiel #7
0
 def main():
     # Create fresh ioloop and make flexx use it
     loop = IOLoop()
     loop.make_current()
     app.create_server()
     # Create model and manipulate prop
     model = MyModel1()
     model.foo = 3
     model.foo = 4
     # Run mainloop for one iterartion
     app.call_later(0, app.stop)
     app.start()
Beispiel #8
0
 def main():
     # Create fresh ioloop and make flexx use it
     loop = IOLoop()
     loop.make_current()
     app.create_server()
     # Create model and manipulate prop
     model = MyModel1()
     model.foo = 3
     model.foo = 4
     # Run mainloop for one iterartion
     app.call_later(0, app.stop)
     app.start()
Beispiel #9
0
def test_flexx_in_thread3():
    """ Test starting and creating server when a server is currently running.
    """
    res = []
    
    def main():
        # Create fresh ioloop and make flexx use it
        loop = IOLoop()
        loop.make_current()
        app.create_server()
        app.start()
    
    def try_start():
        try:
            app.start()
        except RuntimeError:
            res.append('start-fail')
    
    def try_create():
        try:
            main()
        except RuntimeError:
            res.append('create-fail')

    t = threading.Thread(target=main)
    t.start()
    
    # With that thread running ...
    while not app.current_server()._running:
        time.sleep(0.01)
    
    with raises(RuntimeError):
        app.start()
    
    with raises(RuntimeError):
        app.create_server()
    
    t1 = threading.Thread(target=try_start)
    t1.start()
    t1.join()
    
    t2 = threading.Thread(target=try_create)
    t2.start()
    t2.join()
    
    # Stop
    app.stop()  # Start does not work, but we can stop it!
    t.join()  # Otherwise it would never join
    
    # Note that we cannot start it right after calling stop, because it wont
    # stop *at once*. We need to join first.
    
    assert res == ['start-fail', 'create-fail']    
Beispiel #10
0
def test_flexx_in_thread3():
    """ Test starting and creating server when a server is currently running.
    """
    res = []

    def main():
        # Create fresh ioloop and make flexx use it
        loop = IOLoop()
        loop.make_current()
        app.create_server()
        app.start()

    def try_start():
        try:
            app.start()
        except RuntimeError:
            res.append('start-fail')

    def try_create():
        try:
            main()
        except RuntimeError:
            res.append('create-fail')

    t = threading.Thread(target=main)
    t.start()

    # With that thread running ...
    while not app.current_server()._running:
        time.sleep(0.01)

    with raises(RuntimeError):
        app.start()

    with raises(RuntimeError):
        app.create_server()

    t1 = threading.Thread(target=try_start)
    t1.start()
    t1.join()

    t2 = threading.Thread(target=try_create)
    t2.start()
    t2.join()

    # Stop
    app.stop()  # Start does not work, but we can stop it!
    t.join()  # Otherwise it would never join

    # Note that we cannot start it right after calling stop, because it wont
    # stop *at once*. We need to join first.

    assert res == ['start-fail', 'create-fail']
Beispiel #11
0
 def main():
     # Create fresh ioloop and make flexx use it
     # event.loop.reset()
     loop = asyncio.new_event_loop()
     asyncio.set_event_loop(loop)
     app.create_server()
     # Create component and manipulate prop
     comp = MyComponent1()
     comp.set_foo(3)
     comp.set_foo(4)
     # Run mainloop for one iterartion
     loop.call_later(0.2, app.stop)
     app.start()
Beispiel #12
0
 def main():
     # Create fresh ioloop and make flexx use it
     # event.loop.reset()
     loop = asyncio.new_event_loop()
     asyncio.set_event_loop(loop)
     app.create_server()
     # Create component and manipulate prop
     comp = MyComponent1()
     comp.set_foo(3)
     comp.set_foo(4)
     # Run mainloop for one iterartion
     loop.call_later(0.2, app.stop)
     app.start()
Beispiel #13
0
    def inner(simulation):
        if not IMPORTERROR:
            if pypy is not None:

                def simulation(parameters):
                    print("CALLING PYPY")
                    call([
                        pypy, sys.argv[0],
                        json.dumps(parameters), abce.simulation_name
                    ])

            database = dataset.connect('sqlite:///parameter.db')
            abce.parameter_database = database['parameter']
            Form = form(parameter_mask, names)  # pylint: disable=C0103
            if serve:
                flexx.config.hostname = hostname
                flexx.config.port = port
                app.serve(
                    basiclayout(Form,
                                simulation,
                                title,
                                header,
                                truncate_rounds,
                                texts=texts,
                                pages=pages,
                                histograms=histograms))
                app.start()
            else:
                app.launch(basiclayout(Form,
                                       simulation,
                                       title,
                                       header,
                                       truncate_rounds,
                                       texts=texts,
                                       pages=pages,
                                       histograms=histograms),
                           windowmode='maximized',
                           runtime=runtime)
                app.run()
        else:
            print("RUN PYPY")
            abce.simulation_name = sys.argv[2]
            simulation(json.loads(sys.argv[1]))
        return lambda _: None
Beispiel #14
0
def runner(cls):
    
    # Run with a fresh server
    server = app.create_server(port=0, new_loop=True)
    
    t = app.launch(cls, 'firefox-app')
    t.test_init()
    t.test_set_result()
    # Install failsafe. Use a closure so failsafe wont spoil a future test
    isrunning = True
    def stop():
        if isrunning:
            app.stop()
    app.call_later(TIMEOUT1, stop)
    # Enter main loop until we get out
    t0 = time.time()
    app.start()
    print('ran %f seconds' % (time.time()-t0))
    isrunning = False
    # Check result
    if True:  # not (ON_TRAVIS and ON_PYPY):  # has intermittent fails on pypy3
        t.test_check()
    # Shut down
    t.session.close()
Beispiel #15
0
def test_more_stopping():
    """ Test calling stop multiple times.
    """
    
    # This is why you want to create new IOLoop instances for each test
    
    # Create new ioloop and make Flexx use it
    loop = IOLoop()
    loop.make_current()
    server = app.create_server()
    
    app.stop()  # triggers event to stop
    app.start()
    
    app.stop()  # Extra stop - pending stop event
    
    # Which means the next stop does hardly block
    t0 = time.time()
    app.call_later(0.2, app.stop)
    app.start()
    assert time.time() - t0 < 0.1
    
    
    loop = IOLoop()
    loop.make_current()
    server = app.create_server()
    
    # But stops dont stack
    app.stop()
    app.stop()
    app.stop()
    app.stop()
    
    # Flush all stops ...
    app.stop()
    app.start()
    
    # ... so that we now have an expected loop
    t0 = time.time()
    app.call_later(0.2, app.stop)
    app.start()
    assert time.time() - t0 >= 0.1
Beispiel #16
0
def test_more_stopping():
    """ Test calling stop multiple times.
    """

    # This is why you want to create new IOLoop instances for each test

    # Create new ioloop and make Flexx use it
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    server = app.create_server()

    app.stop()  # triggers event to stop
    app.start()

    app.stop()  # Extra stop - pending stop event

    # Which means the next stop does hardly block
    t0 = time.time()
    loop.call_later(0.2, app.stop)
    app.start()
    assert time.time() - t0 < 0.1


    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    server = app.create_server()

    # But stops dont stack
    app.stop()
    app.stop()
    app.stop()
    app.stop()

    # Flush all stops ...
    app.stop()
    app.start()

    # ... so that we now have an expected loop
    t0 = time.time()
    loop.call_later(0.2, app.stop)
    app.start()
    assert time.time() - t0 >= 0.1
Beispiel #17
0
def test_restarting():
    """ Test stopping and starting the ioloop.
    """
    res = []

    def add_res(i):
        res.append(i)

    def try_start():
        try:
            app.start()
        except RuntimeError:
            res.append('RTE')

    # Create new ioloop always
    loop = IOLoop()
    loop.make_current()
    # Make Flexx use it
    server = app.create_server()

    app.call_later(0, add_res, 1)
    app.call_later(0, add_res, 2)
    app.call_later(
        0, app.stop)  # actually, just calling stop() would work as well
    app.start()
    assert server._running == False

    app.call_later(0, try_start)  # test that cannot start twice
    app.call_later(0, add_res, 3)
    app.call_later(0, add_res, 4)
    app.call_later(0, app.stop)
    app.start()
    assert server._running == False

    app.call_later(0, try_start)  # test that cannot start twice
    app.call_later(0, add_res, 5)
    app.call_later(0, add_res, 6)
    app.call_later(0, app.stop)
    app.start()
    assert server._running == False

    assert res == [1, 2, 'RTE', 3, 4, 'RTE', 5, 6]
Beispiel #18
0
def test_restarting():
    """ Test stopping and starting the ioloop.
    """
    res = []

    def add_res(i):
        res.append(i)

    def try_start():
        try:
            app.start()
        except RuntimeError:
            res.append('RTE')

    # Create new ioloop always
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    # Make Flexx use it
    server = app.create_server()

    loop.call_soon(add_res, 1)
    loop.call_soon(add_res, 2)
    loop.call_soon(
        app.stop)  # actually, just calling stop() would work as well
    app.start()
    assert server._running == False

    loop.call_soon(try_start)  # test that cannot start twice
    loop.call_soon(add_res, 3)
    loop.call_soon(add_res, 4)
    loop.call_soon(app.stop)
    app.start()
    assert server._running == False

    loop.call_soon(try_start)  # test that cannot start twice
    loop.call_soon(add_res, 5)
    loop.call_soon(add_res, 6)
    loop.call_soon(app.stop)
    app.start()
    assert server._running == False

    assert res == [1, 2, 'RTE', 3, 4, 'RTE', 5, 6]
Beispiel #19
0
def test_restarting():
    """ Test stopping and starting the ioloop.
    """
    res = []
    def add_res(i):
        res.append(i)
    
    def try_start():
        try:
            app.start()
        except RuntimeError:
            res.append('RTE')
        
    # Create new ioloop always
    loop = IOLoop()
    loop.make_current()
    # Make Flexx use it
    server = app.create_server()
    
    app.call_later(0, add_res, 1)
    app.call_later(0, add_res, 2)
    app.call_later(0, app.stop)  # actually, just calling stop() would work as well
    app.start()
    assert server._running == False
    
    app.call_later(0, try_start)  # test that cannot start twice
    app.call_later(0, add_res, 3)
    app.call_later(0, add_res, 4)
    app.call_later(0, app.stop)
    app.start()
    assert server._running == False
    
    app.call_later(0, try_start)  # test that cannot start twice
    app.call_later(0, add_res, 5)
    app.call_later(0, add_res, 6)
    app.call_later(0, app.stop)
    app.start()
    assert server._running == False
    
    assert res == [1, 2, 'RTE', 3, 4, 'RTE', 5, 6]
Beispiel #20
0
def test_restarting():
    """ Test stopping and starting the ioloop.
    """
    res = []
    def add_res(i):
        res.append(i)

    def try_start():
        try:
            app.start()
        except RuntimeError:
            res.append('RTE')

    # Create new ioloop always
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    # Make Flexx use it
    server = app.create_server()

    loop.call_soon(add_res, 1)
    loop.call_soon(add_res, 2)
    loop.call_soon(app.stop)  # actually, just calling stop() would work as well
    app.start()
    assert server._running == False

    loop.call_soon(try_start)  # test that cannot start twice
    loop.call_soon(add_res, 3)
    loop.call_soon(add_res, 4)
    loop.call_soon(app.stop)
    app.start()
    assert server._running == False

    loop.call_soon(try_start)  # test that cannot start twice
    loop.call_soon(add_res, 5)
    loop.call_soon(add_res, 6)
    loop.call_soon(app.stop)
    app.start()
    assert server._running == False

    assert res == [1, 2, 'RTE', 3, 4, 'RTE', 5, 6]
Beispiel #21
0
        proxies = app.manager.get_connections(self.__class__.__name__)
        names = [p.app.name.text for p in proxies]
        del proxies
        text = '<br />%i persons in this chat:<br /><br />' % len(names)
        text += '<br />'.join([name or 'anonymous' for name in sorted(names)])
        self.people.text = text
        app.call_later(3, self._update_participants)
    
    @event.connect('ok.mouse_down', 'message.submit')
    def _send_message(self, *events):
        text = self.message.text
        if text:
            name = self.name.text or 'anonymous'
            relay.new_message('<i>%s</i>: %s' % (name, text))
            self.message.text = ''
    
    class JS:
        
        @event.connect('new_message')
        def _update_total_text(self, *events):
            self.messages.text += ''.join([ev.msg for ev in events])


# Create global relay
relay = Relay()

if __name__ == '__main__':
    app.serve(ChatRoom)
    # m = app.launch(ChatRoom)  # for use during development
    app.start()
Beispiel #22
0
			self.process = subprocess.Popen(
				["python3", "main.py", "--graphical", "True"] + args, shell=False)
			self.log("Proc. ID: " + str(self.process.pid))
			with open("process.dat", "w") as f:
				f.write(str(self.process.pid))

	@react.connect("quit.mouse_down")
	def _handle_quit(self, down):
		if down:
			try:
				os.remove("process.dat")
			except FileNotFoundError:
				pass
			self.kill_process()
			sys.exit()

	@react.connect("stop.mouse_down")
	def _handle_stop(self, down):
		if down:
			try:
				os.remove("process.dat")
			except FileNotFoundError:
				pass
			self.kill_process()

# app.serve(LightFX_Controller)
main = app.launch(LightFX_Controller)
# main()
if __name__ == "__main__":
	app.start(port=8080)
Beispiel #23
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2018/1/3 15:59
# @Author  : yc
# @Site    :
# @File    : 16_group.py
# @Software: PyCharm

from flexx import app, ui, event


class Example(ui.GroupWidget):
    def init(self):
        self.title = 'A silly panel'
        with ui.VBox():
            self.progress = ui.ProgressBar(value=0.001)
            self.but = ui.Button(text='click me')

    class JS:
        @event.connect('but.mouse_down')
        def _change_group_title(self, *events):
            self.progress.value += 0.05


app.init_interactive(Example)
app.create_server(host="127.0.0.1",
                  port=8009,
                  new_loop=False,
                  backend='tornado')
app.start()
Beispiel #24
0
 def main():
     # Create fresh ioloop and make flexx use it
     loop = asyncio.new_event_loop()
     asyncio.set_event_loop(loop)
     app.create_server()  # calls event.loop.integrate()
     app.start()
Beispiel #25
0
 def main():
     # Create fresh ioloop and make flexx use it
     loop = asyncio.new_event_loop()
     asyncio.set_event_loop(loop)
     app.create_server()  # calls event.loop.integrate()
     app.start()
Beispiel #26
0
def start_flexx():
    app.create_server(loop=asyncio.new_event_loop())
    app.start()
Beispiel #27
0
 def main():
     # Create fresh ioloop and make flexx use it
     loop = IOLoop()
     loop.make_current()
     app.create_server()
     app.start()
Beispiel #28
0
def multiprocessing_func():
    import flexx
    app.create_server(port=0)  # Explicitly ask for unused port
    app.call_later(0.1, app.stop)
    app.start()
Beispiel #29
0
 def try_start():
     try:
         app.start()
     except RuntimeError:
         res.append('RTE')
Beispiel #30
0
 def main():
     app.stop()
     app.start()
     assert server.loop is IOLoop.current()
     res.append(3)
Beispiel #31
0
 def try_start():
     try:
         app.start()
     except RuntimeError:
         res.append('start-fail')
Beispiel #32
0
 def try_start():
     try:
         app.start()
     except RuntimeError:
         res.append('RTE')
Beispiel #33
0
 def try_start():
     try:
         app.start()
     except RuntimeError:
         res.append('start-fail')
Beispiel #34
0
 def main():
     # Create fresh ioloop and make flexx use it
     loop = IOLoop()
     loop.make_current()
     app.create_server()
     app.start()
Beispiel #35
0
 def main():
     app.stop()
     app.start()
     assert server.loop is IOLoop.current()
     res.append(3)
Beispiel #36
0
def multiprocessing_func():
    import flexx
    app.create_server(port=0)  # Explicitly ask for unused port
    app.call_later(0.1, app.stop)
    app.start()