Alexa ( was: Re: XTension won't stay quitted)

James Sentman james at sentman.com
Thu Jul 20 15:01:56 EDT 2017


I have wasted a portion of the afternoon trying to get threading working within python inside of XTension and it’s a wash. I can get it to work, but as soon as it calls back into anything in the host app it crashes so thats not very useful.

The solution I think at the moment anyway is to use a timer to poll the socket as you’ve already suspected. Most socket based servers that I’ve experimented have 2 different methods to make them actually do something. Most of the demos seem to call the someServer.serve_forever() method, which requires that you have that called on a thread. However, you can set a timeout and repeatedly call the lower level someServer.handle_request() call from a timer and that seems to work just fine!

instead of calling server_forever you set the someServer.timeout=0.1 and then setup a timer to callback every 100 or 200 ms (or longer if time isn’t completely important) to some method that just does:

def timerCallback():
  global aServerReference
  aServerReference.handle_request()

but you DO have to save off your server into a global variable so that it can be found by the callback. I’ve tested this with the demo of the XMLRPC server and it works a treat.

I will have some incoming support in the next version but it’s not going to be for UDP packets yet so it won’t help you with this. I am going to add the ability to create servers and outgoing connections in python code though so you’ll be able to use that, or the python only method mentioned above to do such receptions.

Can you tell me more about this “hue hub” emulation? 


> On Jul 20, 2017, at 2:04 PM, Dean Davis <afterten at gmail.com> wrote:
> 
> Looks like I could use XTMakeTimer for the UPNP broadcast packets. Example code I'm looking at uses a threading.Thread so it doesn't sound like I could use that but looks like I could put that code into a timer.
> 
> I'll keep messing.

Thanks,
 James


James Sentman                       http://www.PlanetaryGear.org		http://MacHomeAutomation.com




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.machomeautomation.com/pipermail/xtensionlist/attachments/20170720/4657a1f0/attachment.html>


More information about the XTensionList mailing list