[BlackBerry-Python] Design question re BlackBird (browser-based app inspector tool for Tart)

Peter Hansen peter at engcorp.com
Mon Sep 23 10:24:41 EDT 2013


So I spent the weekend learning WebSockets and implementing a 
proof-of-concept for "BlackBird". This is to be a "web inspector" type 
of utility that you can run in your browser to monitor the status of an 
app running on a device, poke at it, watch the log output, view live 
thread activity, maybe run Pdb in post-mortem mode, get an interactive 
Python console running in the context of the app, and probably even a 
JavaScript console running in the context of the QML as well. And just 
about anything else we can imagine.

My first stab at this uses bottle.py (a decent little web 
micro-framework) with its own simple templating language to serve up 
some CSS, HTML, and JS to your browser. The client code can use the 
WebSocket API to connect back to the app, where I've hacked on top of 
bottle and WSGI an async WebSocket handler hooked into the app with a 
Queue. It even works. ;-)

My question is whether that's an appropriate architecture. I'm now 
thinking it might make more sense to keep the web-server part out of the 
app, and have it be local to your dev environment, where you'd maybe 
just run "tart blackbird" and it would launch a local server (and your 
browser, opening it at the starting page). Same code could be used 
(bottle + templates etc) but it wouldn't be in the app. The app would 
have only the WebSocket service running, and none of the web stuff.

With the existing model, you can connect from any browser any time... 
the app hosts everything itself.  The disadvantage is if the app fails, 
you can't get your initial connection so there's no web page to view.

With the alternate approach, you need to run the server somewhere 
yourself, but it would let you load the BlackBird web app whether or not 
your app was running, and could act independently of it. For example, 
you could possibly do some degree of post-mortem analysis of failures 
even if the app had crashed, like on the latest log entries that were 
received. It could auto-reconnect to the app once it restarted, but 
preserve the older data as well, maybe even using WebStorage to persist it.

Thoughts?

-Peter

P.S. BlackBird comes from the old rhyme "Four and twenty blackbirds, 
baked in a 'Py'..."  ;-) It seemed appropriate when I was first 
picturing it as a set of diagnostic tools (24 of them?) "baked" into a 
Tart app...  http://en.wikipedia.org/wiki/Sing_a_Song_of_Sixpence


More information about the BlackBerry-Python mailing list