Sunday, 4 October 2015

Can I call 32-bit python from an ArcGIS Server 10.3.1 GP Service?


I've developed a geoprocessing service that accepts a personal geodatabase as an attachment. After this MDB is copied to the server, I'd like to use ArcPy to open it, edit some feature classes, then append the data to an existing SDE dataset.


Given that ArcGIS Server GP Services are running 64 bit python, I tried using a subprocess to call 32 bit python:


try:
arcpy.AddMessage(subprocess.check_output(["C:\Python27\ArcGIS10.3\python", \
"D:\Data\GISData\Scripts\CheckFCExists.py", newSourceData]))


except subprocess.CalledProcessError, e:
arcpy.AddMessage('It failed!')
arcpy.AddMessage("Subprocess output: {0}".format(e.output))

When running as a script tool in ArcGIS Desktop, the subprocess completes successfully with the STDOUT printed via arcpy.AddMessage.


When published as a GP service, it fails. The code enters the except block, prints 'it fails!' and then "Subprocess output", indicating that e.output is empty.



Answer



Based on some research, heres a half answer on the problem with some general thoughts.





  • I'm almost positive you need to make a Python call that doesn't open a new window. As indicated in my previous comments, I'm pretty sure a new window opening on an account that isn't actively logged in will not work. The following code seems to launch the other python process without opening a new active window:


    command2 = ["c:/python27/arcgis10.3/python.exe", 'C:/gpServices/CallSubProcess/calledCode.py']


    start = subprocess.STARTUPINFO()


    start.wShowWindow = 0


    start.dwFlags |= subprocess.STARTF_USESHOWWINDOW


    callReturn = subprocess.Popen(command2, startupinfo=start).wait()




  • In a plain install, the GP Service will raise a security error in the windows event logs when it tries to call the 32bit Python. By default, the user account created for ArcGIS Server is assigned only the permissions it absolutely requires to run, nothing more. So it makes sense that Server can't access executable/files outside its installation directory.




  • Elevating the ArcGIS Server user account from a basic "user" to "administrator" and re-starting Server gets passed the security error, but still fails in the service.

    • Interestingly enough, I could open a command window as the Server user and run Python. So the account seems to have at least basic permissions...



  • It seems most likely a security setting on the machine itself, but I dont see anything in the event viewer. I'm not an expert in user permissions, but to me, this is probably the area to investigate as the block.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...