我无意中创造了科学怪人。
一切都在解释器中运行良好,但在运行python pyinstaller.py --onefile myFile.py
生成 .exe 后,运行时它开始出现奇怪的行为。它似乎随机调用它的main()
函数——即使在键盘中断爆发后,它也会自我复活。
代码如下所示:
def main():
print 'DO NOT CLOSE!'
count = 0
lastTime = ((time.localtime()[4])*60) + (time.localtime()[5])
sShot = ImageGrab.grab()
saveSnap(count, lastTime)
currentScreen = grab()
while True:
if currentScreen == grab():
pass
else:
count += 1
saveSnap(count, lastTime)
currentScreen = grab()
lastTime = ((time.localtime()[4])*60) + (time.localtime()[5])
if __name__ == '__main__':
main()
非常简单的东西,就像我说的,它在解释器中运行良好。它所做的只是在屏幕上搜索更改,然后为快照添加时间戳。
什么会导致随机开火main()
?它有时甚至在键盘中断之前就会这样做。