アプリケーションを 100 回実行して動作中のスクリーンショットを撮ってテストしたいと考えています。それが私が思いついたものです:
import sys, string, os
import time
import wx
directory = 'my path to directory containing the .exe'
file = '"directory and .exe path"'
app = wx.App(False)
screen = wx.ScreenDC()
size = screen.GetSize()
def runprogram(number,sleep_time):
bitmap = wx.EmptyBitmap(size[0], size[1])
mem = wx.MemoryDC(bitmap)
newfile = str(number) + "_" + str(sleep_time)
print newfile
os.chdir(directory)
os.system(file)
time.sleep(sleep_time) #seconds
print "sleeping done"
mem.Blit(0, 0, size[0], size[1], screen, 0, 0)
del mem
bitmap.SaveFile(newfile, wx.BITMAP_TYPE_PNG)
print "file saved as "+ newfile
os.system("TASKKILL /F /IM myprogram.exe")
runprogram(1,5)
問題は、os.system() が実行されると、プログラム ウィンドウを閉じるまでスクリプトが停止し、その後スリープしてスクリーンショットを撮ることです。これらのアクションを同時に実行したいのです。どうやってやるの?