#! /usr/bin/env python
# -*- coding: utf-8 -*-
import pickle
dev = indigo.devices[66959601]
dev_props = dev.ownerProps
dev_dict = dict(dev_props) # You can't pickle an indigo.Dict() object, so convert it first.
dev_pickle = pickle.dumps(dev_dict)
indigo.server.log(repr(dev_pickle)) # A
dev_unpickle = pickle.loads(dev_pickle)
indigo.server.log(repr(dev_unpickle)) # B
Script '(dp0\nVdayOfWeekFormat\np1\nVmid\np2\nsVfirstDayOfWeek\np3\nV6\np4\nsVdayOfWeekAlignment\np5\nVright\np6\nsVfileName\np7\nVchart_calendar.png\np8\nsVcustomSizeHeight\np9\nVNone\np10\nsVfontSize\np11\nI12\nsVcalendarGrid\np12\nI01\nsVisChart\np13\nI01\nsVrefreshInterval\np14\nV60\np15\nsVcustomSizeWidth\np16\nVNone\np17\ns.' # A
Script {u'customSizeHeight': u'None', u'firstDayOfWeek': u'6', u'dayOfWeekAlignment': u'right', u'fileName': u'chart_calendar.png', u'dayOfWeekFormat': u'mid', u'fontSize': 12, u'calendarGrid': True, u'isChart': True, u'refreshInterval': u'60', u'customSizeWidth': u'None'} # B
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import pickle
pickle.dump(sys.argv, sys.stdout) # This is the data returned to the parent if everything goes well
raise ValueError(u"This is the error text to display.")
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import subprocess
import pickle
path_to_file = '/Users/Dave/PycharmProjects/development/test1.py'
proc = subprocess.Popen(['python2.7', path_to_file, 'foo', 'bar',],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
# Note reply is a pickle, err is a string
reply, err = proc.communicate()
reply = pickle.loads(reply)
print(repr(reply)) # A
print(type(reply)) # B
print(err) # C
print(proc.returncode) # D
['/Users/Dave/PycharmProjects/development/test1.py', 'foo', 'bar'] # A
<type 'list'> # B
Traceback (most recent call last):
File "/Users/Dave/PycharmProjects/development/test1.py", line 9, in <module>
raise ValueError(u"This is the error text to display.")
ValueError: This is the error text to display. # C
1 # D
plugin.py calls: proc = subprocess.Popen(['python2.7', path_to_file, payload, ], stdout=subprocess.PIPE, stderr=subprocess.PIPE )
path_to_file is a reference to a child script, say foo.py which is located in the plugin package
foo.py handles needed imports -- including other python scripts located within the plugin package -- even if they've already been imported into plugin.py
foo.py does its thing in its own process -- thereby "protecting" the plugin process
foo.py collects return data along the way and returns it in a pickle through stdout
I chose to send exception messages through stdout rather that stderr so that foo.py had a chance to finish.
Uncaught exceptions will come through stderr
Process return data and messages in plugin.py
Users browsing this forum: No registered users and 4 guests