Python script runs fine for a while then returns MemoryError (python 3.3) -


i have small script utilizes python imaging library module python3.3 (on win7, 8 gb of ram) take screenshot of small (~40x50) pixel area of screen once each second , compare image have detect particular pattern , execute 2 other modules created if found. script seems work flawlessly first 30 minutes or so, script crashes , following error:

traceback (most recent call last):
file "<string>", line 420, in run_nodebug
file "c:\users\nate simon\dropbox\captchalibrary\detectnrun.py", line 68, in <module>:
im2 = imagegrab.grab((left,upper,right,lower))
file "c:\python33\lib\site-packages\pil\imagegrab.py", line 47, in grab:
size, data = grabber()
memoryerror

i've adjusted time between screenshots , delay when program crashes.

here seems offending code:

im2 = imagegrab.grab((left,upper,right,lower)) # take screenshot @ given coordinates  x in range(im2.size[0]): # section changes image black/white better comparing might relevant.     y in range(im2.size[1]):         pixel = im2.getpixel((x,y))         if pixel[0] < 40 or pixel[1] < 40 or pixel[2] < 40:             color = (0, 0, 0)         else:             color = (255, 255, 255)         im2.putpixel((x,y), color) 

there no lists, dictionaries, or databases being added in script, every time runs old screenshot overwritten in memory (it never saved disk).

also possibly relevant: time module using sleep() delays , time() keep track of system time. using win32api mouse/keyboard inputs , using tkinter read clipboard in following lines:

    c = tk()     c.withdraw()     result = c.clipboard_get()     c.destroy() 

in section, clipboard cleared before new data added c.clipboard_clear()

i unable find adequate solution solve memory issue (or replicate under different conditions), increased interval between actions 1 second 15 seconds , have yet memory error again.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -