def __init__(self): Thread.__init__(self, daemon=True) def run(self): delta = random.uniform(0.05, 0.5) self.emit('started', self.uuid, time.time()) for i in range(100): time.sleep(delta) self.emit('progress', self.uuid, i) self.emit('complete', self.uuid, time.time()) app = App(name="Lens. Threads") # load the app entry page app.namespaces.append('./sample-data/app-threads') @app.bind('close') def _close_app_cb(*args): app.close() @app.bind('get-hostname') def _get_hostname_cb(*args): app.emit('update-config', os.uname()[1])
#! /usr/bin/env python3 import platform from lens.app import App app = App() # bind to the 'close' signal @app.bind('close') def _close_app_cb(*args): app.close() # bind to the 'get-hostname' signal @app.bind('get-hostname') def _get_hostname_cb(*args): app.emit('update-hostname', platform.node()) # start the app event loop app.start(""" <!DOCTYPE html> <html lang="en"> <head> <link href="lens://css/lens.css" rel="stylesheet"> </head> <body> <h1>Lens. Demo</h1> <p>This sample demonstrates simple communication between the Python and JS code paths.</p> <p>Hostname: <span id="hostname"></span></p>
'mem_shared': int(statm[2]), 'mem_percentage': round(int(statm[1]) * 100.0 / int(meminfo[0]), 2) }) except: # proc has already terminated continue self.emit('proc-update', proc) time.sleep(5) app = App(inspector=True, name='LensTop') # load the app entry page app.namespaces.append('./sample-data/app-top') @app.bind('close') def _close_app_cb(*args): app.close() @app.bind('start-proc-watch') def _start_proc_watch_cb(*args): t = ProcTask() t.daemon = True app.threads.add(t)