exec code with timeout?
JCM
joshway_without_spam at myway.com
Mon Sep 8 17:46:47 EDT 2003
"OKB (not okblacke)" <BrenBarn at aol.com> wrote:
> I am fiddling around with a Python-based MUD which allows users to
> code MUD objects in Python. This code is executed from within the
> server code with "exec". However, sometimes errors in user code can
> result in infinite loops, which cause the MUD to hang. I am wondering
> if there is a way to put a timeout on the exec, so that it returns
> control to the main program if the user code doesn't return within a
> certain amount of time.
We've done exactly this for our own MUD project :)
The way we got around the infinite loop problem was to have the main
Python thread be the one that runs all unknown MUD-code. You can use
signals (on unix) to raise an exception in the main thread. I don't
remember offhand what function we used--maybe os.kill?
More information about the Python-list
mailing list