Watchdog technique
Terry Hancock
hancock at anansispaceworks.com
Mon Aug 18 12:52:57 EDT 2003
Hi all,
I have a program in a webserver environment that needs to run a fairly
intensive calculation, which involves C extension calls (image processing
with PIL). Most of the time, this works fine, but every once in awhile the
calculation will hang, and I can't afford to wait for it (it's better to
ditch it and get no result). This is a classic "heartbeat" or "watchdog"
problem.
I'm currently trying this with code like this:
regen_thread = threading.Thread(...)
regen_thread.start()
regen_thread.join(REGEN_TIMEOUT)
Which, on the surface, seems like the obvious way.
But I'm concerned that there's no mention in the library reference
of whether the regen_thread still exists after the join (if it times out).
And, searching the archives, I see that Will Stuyvesant apparently had this
same problem in late 2002. His posts seem to indicate that the
regen_thread will be left running -- in my case this could eat up system
resources, and eventually cause essentially a DOS situation on the server
-- especially as I do not know in advance what might've gone wrong in the
regeneration (e.g. it might be stuck in an infinite loop inside an
extension call). Obviously, that would be bad.
So, my question is: is there a better way?
Thanks for any advice,
Terry
--
Terry Hancock
Anansi Spaceworks http://www.AnansiSpaceworks.com/
More information about the Python-list
mailing list