import maya.cmds as cmds
cmds.progressWindow(isInterruptable=1)
while 1 :
print "kill me!"
if cmds.progressWindow(query=1, isCancelled=1) :
break
cmds.progressWindow(endProgress=1)