unbuffered print() to ArcMap Python window?

2248
1
08-29-2014 08:05 AM
theMC5
by
New Contributor

I have a Python Add-In for ArcMap. Add-Ins don't have access to a progress bar (see Adding messaging to Python Add-in ). Plan B - I am writing messages during a lengthy loop to the Python window using print(mymsg). But nothing appears in the Python window during the loop, then suddenly all the messages appear at the end of the loop. Less than helpful! Sounds like a buffered stdout?

So I tried doing sys.stdout.flush() after each print(), and I get this: AttributeError: 'geoprocessing sys.stdout object' object has no attribute 'flush'. I guess that's how the Python window works - ArcMap resets stdout to a custom object that buffers, but lacks a flush() method.

Whatsa guy to do?  Thanks!

Tags (2)
0 Kudos
1 Reply
DarrenSmith
New Contributor III

I'm getting a similar problem when I run a custom script totally outside of ArcMap (ArcGIS 10.1 SP1 Build 3143). I use ' sys.stdout.flush()' several times without problem in the code (after running various arcpy gp tools and functions etc.) before the point that crashes without a problem.

Upon examination it seems that the standard sys.stdout python class is overwritten during a call to the arcpy.CalculateField_management gp tool (where I use a Python codeblock to calculate the field values). The new sys.stdout has no flush() method, hence the error. This seems like a pretty fundamental bug to me.

0 Kudos