def _update_participants(self): proxies = app.manager.get_connections(self.__class__.__name__) names = [p.app.name.text() for p in 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)
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()
def runner(cls): t = app.launch(cls, 'firefox') t.test_init() app.call_later(5, app.stop) app.run() if not (ON_TRAVIS and ON_PYPY): # has intermittent fails on pypy3 t.test_check()
def tick(self): t = time.time() for i, circle in enumerate(self._circles): x = math.sin(i*0.2 + t)*0.3 + 0.5 y = math.cos(i*0.2 + t)*0.3 + 0.5 circle.pos((x, y)) app.call_later(0.03, self.tick)
def runner(cls): t = app.launch(cls, 'firefox') # fails somehow with XUL t.test_init() app.call_later(TIMEOUT1, app.stop) app.run() if not (ON_TRAVIS and ON_PYPY): # has intermittent fails on pypy3 t.test_check() t.session.close()
def _update_participants(self): """ Keep track of the number of participants. """ if not self.session.status: return # and dont't invoke a new call proxies = app.manager.get_connections(self.__class__.__name__) n = len(proxies) del proxies self.people.text = '%i persons are painting' % n app.call_later(3, self._update_participants)
def _update_participants(self): if not self.session.status: relay.disconnect('new_dot:' + self.id) return # and dont't invoke a new call proxies = app.manager.get_connections(self.__class__.__name__) n = len(proxies) del proxies self.people.text = '%i persons are painting' % n app.call_later(3, self._update_participants)
def tick(self): if not self.session.status: return import time t = time.time() for i, circle in enumerate(self._circles): x = math.sin(i * 0.2 + t) * 0.3 + 0.5 y = math.cos(i * 0.2 + t) * 0.3 + 0.5 circle.pos = x, y app.call_later(0.03, self.tick)
def _update_participants(self): if not self.session.status: return # and dont't invoke a new call sessions = app.manager.get_connections(self.session.app_name) names = [p._chatroom_name for p in sessions] # _chatroom_name is what we set del sessions 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)
def _update_participants(self): if not self.session.status: return # and dont't invoke a new call 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)
def _update_participants(self): if not self.session.status: relay.disconnect('new_message:' + self.id) return # and dont't invoke a new call 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)
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()
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
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()
def result(self, v=None): if v: #app.stop() print('stopping by ourselves', v) app.call_later(TIMEOUT2, app.stop) return v
def test_init(self): app.call_later(0.2, self._emit_foo) app.call_later(0.3, lambda:self.call_js('set_result()'))
def multiprocessing_func(): import flexx app.create_server(port=0) # Explicitly ask for unused port app.call_later(0.1, app.stop) app.start()
def refresh(): global_cpu_usage._set(psutil.cpu_percent()) app.call_later(1, refresh)
def refresh(): global_cpu_usage._set(psutil.cpu_percent()) global_mem_usage._set(psutil.virtual_memory().percent) app.call_later(1, refresh)
def result(self, v=None): if not this_is_js(): if v: print('stopping by ourselves', v) app.call_later(TIMEOUT2, app.stop) return v
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]
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]
def refresh(self): self.system_info() app.call_later(1, self.refresh)