Monday, January 23, 2012

DateTimer: Python class to easily report stop, start and elapsed time

Here is a simple class to make reporting start, finish and elapsed time easy.  If you are running python scripts at command line, this utility will make it easier to keep track of the progress of your processing.
Here is an example of usage:
from arcpyh import DateTimer
import time

timer = DateTimer()
Here is an example of the output:
Started: 2012-01-23 14:50:00
Finished: 2012-01-23 14:50:10 (Elapsed: 0:00:10)
Here is the important code.  Save this in a file called “” and put it in the same directory of the script you are running or elsewhere in your pythonpath.
from datetime import datetime

class DateTimer:
    ''' Handy timer that reports start time, end time and delta time

        report:(default=True) If True, prints automatically

        Example output:

            Started: 2012-01-23 14:40:37
            Finished: 2012-01-23 14:40:47 (Elapsed: 0:00:10)


    NO_START_MSG = "Timer was never started."
    FINISH_MSG = "Finished: {0} (Elapsed: {1})"
    START_MSG = "Started: {0}"

    def __init__(self, report=True): = report
        self.startDateTime = None
        self.endDateTime = None
        self.deltaTime = None

    def start(self):

        self.startDateTime =
        self.endDateTime = None


    def stop(self):
        self.endDateTime =
        if self.startDateTime:
            self.deltaTime = self.endDateTime - self.startDateTime


    def printStart(self):
        if self.startDateTime:
            print self.START_MSG.format(self.datetimeToString(self.startDateTime))
            print self.NO_START_MSG

    def printEnd(self):
        if self.deltaTime:
            print self.FINISH_MSG.format(self.datetimeToString(self.endDateTime), self.deltaToString(self.deltaTime))
            print self.NO_START_MSG

    def datetimeToString(self, dateTimeObject):
        return str(dateTimeObject).split(".")[0]

    def deltaToString(self, delta):
        return str(delta).split(".")[0]

Thursday, January 19, 2012

Set 32bit Executable LARGEADDRESSAWARE Flag to True

If a 32bit executable does not have the LARGEADDRESSAWARE flag set to true, the application can't use more than 2 gigabytes. If you are on a 64bit machine with lots of memory, even if you are stuck with a 32bit process, you should ideally be able to start multiple processes each using 3+ gigabytes.

For example, the 32bit version of python is not large address aware. You might ask why use 32bit Python on a 64bit machine? Unfortunately, some third party vendors like ESRI have been slow to update to 64bit. ArcGIS Server is 64bit at 10.1, but ArcGIS Desktop remains 32 bit. We can only access their arcpy python module from 32bit Python.

Well, we can at least give our 32bit Python process a little more memory to play with:

1. Verify Visual Studio Installed
This routine was only tested using Visual Studio 2010 Professional. If you have success with Visual Studio C++ Express, please leave a comment.

2. Launch Visual Studio Command Prompt

From Start Menu: All Programs > Microsoft Visual Studio 2010 > Visual Studio Tools > Visual Studio Command Prompt (2010)
From console (cmd.exe):
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86

In either case, you should see the following message:
Setting environment for using Microsoft Visual Studio 2010 x86 tools.

3. Backup your executable

You might want to swap the old executable back if you experience unexpected issues!

4. Execute command to set the LARGEADRESSAWARE flag to true:
editbin /LARGEADDRESSAWARE "C:\Python26\ArcGIS10.0\python.exe"

If the executable is locked, copy it to a temporary directory, then overwrite original when process locking executable has finished.

5. Check that it worked
dumpbin /headers "C:\Python26\ArcGIS10.0\python.exe" | more
You should see "...Application can handle large (>2GB) addresses..."
6. Reflection Time
Ok, our hope is that we can now launch 32bit python processes that can access more than 2gb of ram. Given Murphy's Law, I'm sure we can guarantee that there will be at least some instances where this causes issues. See the third reference below for a discussion on the merits of what we just did. Personally, I like to live on the raggedy edge, but I plan on keeping the backup of the original handy to swap back in if ever needed.


Saturday, January 14, 2012

Windows 7 Burn ISO option not available

If Windows 7 doesn't give you an option to burn an ISO image after right clicking on the .iso file in windows explorer, make a burn.reg text file and paste in the following, save, and then double click on the file.

Windows Registry Editor Version 5.00


@="Disc Image File"






  1. Windows 7 Burn ISO option not available: