Since the signal module is not supported in the python version of Google App Engine, what is the simplest way to call a method and throw/catch an exception if the method does not return in less than 2 seconds?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
If you are talking about RPC calls, such as the datastore, you can create an RPC with a deadline (see
create_rpc
), pass the RPC to your datastore function (db.get, db.put, etc...), then catchDeadlineExceededErrors
.The URLFetch fetch function also takes a deadline parameter.
For your own code you could implement checking yourself, see the time module.
In loops, you can store the time the loop started and check how long it's been going on each iteration.
If you're not in a loop, things are a bit trickier. You could add the time-checking bit every few lines of code. This, of course, makes for really ugly code, but without the ability to spawn threads that could run a timer in the background and interrupt the running code, there's not much of a way around it.