Once again down that hole

Posted on
Tue Jun 12, 2018 7:34 pm
Different Computers offline
User avatar
Posts: 1838
Joined: Jan 02, 2016
Location: East Coast

Re: Once again down that hole

So very very close, AND I've greatly simplified the mess.

But (and there's always a but) I have a problem with what I think is effectively simultaneous execution. The first part of my script takes time, because it involves network activities:
Code: Select all
from PIL import Image
import subprocess
import time
pic_destination = "/Library/Application Support/Perceptive Automation/Indigo 7/IndigoWebServer/public/whatever.PNG"
subprocess.Popen("wget --user name --password value --no-check-certificate 192.168.999.999/cgi-bin/currentpic.cgi -O /Library/Application\ Support/Perceptive\ Automation/Indigo\ 7/IndigoWebServer/whatever.PNG", shell=True)


But as I think I read somewhere, Python executes everything as fast as it can, rather than in order. So any time I've run this after the first, this part acts on the previous image before the new image is saved:
Code: Select all
time.sleep(5). <--------even with this ridiculous value
pic = Image.open(pic_destination)
pic.save("/Library/Application Support/Perceptive Automation/Indigo 7/IndigoWebServer/public/whatever.PNG", optimize=True, quality=80, format='PNG')


To be clear, I'm grabbing an image from the camera, and then want to reduce its quality and size. Right now, the action group is reducing the PREVIOUS image, which is then overwritten immediately by the new image. I know this because I'm watching that Finder directory, and when I run this, the old image drops in size by 70 % or so, and then is overwritten.

But now I'm doubly confused because I just read this suggesting Python executes from top to bottom.

SmartThings refugee, so happy to be on Indigo. 10.13.6 on an i5 MBP w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKit Bridge, MatplotLib, Plex, uniFAP, Wunderground, Nanoleaf, LED Simple Effects, Airfoil Pro, Grafana.

Posted on
Tue Jun 12, 2018 8:35 pm
berkinet offline
User avatar
Posts: 3097
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Once again down that hole

Try something like this...
foo = subprocess.Popen(“command.....
foo.wait

Posted on
Thu Jun 14, 2018 8:33 am
Different Computers offline
User avatar
Posts: 1838
Joined: Jan 02, 2016
Location: East Coast

Re: Once again down that hole

foo.wait seems to have gotten me to the point where I could troubleshoot my other issues.

I still see some weird timing stuff happening, but between adding .wait and sleep commands, it is now working!

Many thanks to everyone who commented.

Oh, and for those wondering, this code integrates, at a very basic level for now, the Wyze V2 camera and the Wyze Cam Pan with the Xiomi/Dafang hacked firmware. With the hack, these cameras are an extraordinary value/feature combination that I highly recommend. Excellent images, full-featured. In fact, most of this Python was needed because the images were too high quality straight from the cameras, and needed to be stepped down for IWS to serve them over the reflector!

SmartThings refugee, so happy to be on Indigo. 10.13.6 on an i5 MBP w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKit Bridge, MatplotLib, Plex, uniFAP, Wunderground, Nanoleaf, LED Simple Effects, Airfoil Pro, Grafana.

Who is online

Users browsing this forum: No registered users and 1 guest

cron