Select to view content in your preferred language

Some questions regarding arcgis10

550
1
04-06-2010 10:19 PM
FrankPerks
New Contributor II
1. If the user does not have .py files associated with the python interpreter (or associating it with something like paint or something stupid), Running a toolbox script with "Run Python Script in process" disabled. In 9.3.1 ArcGIS simply just invoked the file. However if .py files are not associated with the python interpreter, this causes some issues. (This is a huge issue at my university where we cannot modify file associations).

Has it been changed so ESRI invokes python.exe <script>?

(just to clarify, these scripts should be run "Run Python Script in Process" enabled.)

Now just try two small tests.

2. Make a toolbox, make a script, with simply this:

# If this gives an exception, it indicates the script is being executed via eval/exec
__file__


lemme know what happens.

3. Just modify the script from the above step and paste this, and run it.
import arcgisscripting

if __name__ == '__main__':
    import timeit
    gp = arcgisscripting.create()
    gp.addmessage("TIME %s" % str(timeit.default_timer())) 


Note the number, now wait ~15ish seconds. Run it again, what is the time value?

In 9.3.1 this behavior is observed:

Executing: Script
Start Time: Wed Apr 07 01:56:34 2010
Running script Script...
TIME 2.0952383613e-006
Completed script Script...
Executed (Script) successfully.
End Time: Wed Apr 07 01:56:34 2010 (Elapsed Time: 0.00 seconds)

Executing: Script
Start Time: Wed Apr 07 01:56:52 2010
Running script Script...
TIME 17.3807963722
Completed script Script...
Executed (Script) successfully.
End Time: Wed Apr 07 01:56:52 2010 (Elapsed Time: 0.00 seconds)


The behavior observed above (Notice the TIME values), is not really what you would expect. Since you expect  that a geoprocessor script starts then ends. In the past this has caused some serious issues, with a few libraries.

and a few questions about arcpy

4. Does dir() work? or are a lot of parameters still generated at run time?

5. is arcpy running off the same .net based com interopt as arcgisscripting?

6. Do stdout/stderr streams work when run through arcmap?

7. Do assertion errors finally cause the geoprocessor script to abort?

Thanks.
0 Kudos
1 Reply
JasonScheirer
Regular Contributor II
1. I'll look into it, but I suspect this is by design.
2. __file__ will work with script tools and validation scripts in ArcGIS 10.0 final.
3. Cleanup after running script tools can give unexpected results -- the Python interpreter caches imported modules in each process, so per-module locals can hang around (yielding your timeit issue). We've taken pains to minimize the effect and clean up where possible, but for all intents and purposes do not rely on any behavior that makes assumptions on the state of a local variable in a module, and make sure you always instantiate brand new objects per script tool (use timeit.Timer() instead, or use the starttime = time.time(); dostuff(); elapsed_time = time.time() - starttime idiom).
4. dir() will work with most objects now. A majority of arcpy is written in Python so that standard documentation tools like the help() builtin and pydoc will also correctly inspect and report on the objects.
5. It is a C++ Python library interfacing with COM natively, with coarse-grained Python objects built on top of it. It is indeed built on top of arcgisscripting.
6. Yes. There is even a degree of intelligence added so that GP messages will go to stdout/stderr when run out of process in a Python script. Running Python scripts with prints in the Python window will behave as expected. I recommend the Python logging API for anything particularly sophisticated.
7. They should, like any other exception.
0 Kudos