This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients mouad, neologix, vstinner
Date 2011-06-25.22:09:30
SpamBayes Score 0.0
Marked as misclassified No
Message-id <1309039771.74.0.357591759355.issue12410@psf.upfronthosting.co.za>
In-reply-to
Content
alarm() is one possible implementation, but Charles-François listed some drawbacks.

You can also use resource.setrlimit(RLIMIT_CPU), but the timeout is the CPU time (e.g. you cannot stop a sleep) and it is not portable (e.g. resource is not available on Windows).

Another possible implementation is a thread. faulthandler uses an "hidden" thread (implemented in C): a thread ignoring all signals using pthread_sigmask. Python threads are not reliable for a timeout because of the GIL, and it is not easy to "interrupt" another thread from the "timeout" thread. For example, you cannot (easily) raise an exception in another thread.

> I'm not sure there's a reliable way to write such a general-purpose
> wrapper

I agree, but it doesn't mean that it is not possible :-)

I think that you should try to implement in C a thread ignoring all signals. It becomes more complex when you have to implement the "interrupt the current thread" (current thread, or maybe the thread using the operation_timeout context manager?) part.

I suppose that you will have to use low-level "tricks" and you will have to experiment your tool on different platform.

You should start this project outside CPython (as a third party module), and then ask for an integration when your work is well tested. You have to know that a module "dies" when it enters CPython: you have to wait something like 18 months to modify it, so you have to be sure that your code is "correct" ;-)
History
Date User Action Args
2011-06-25 22:09:31vstinnersetrecipients: + vstinner, neologix, mouad
2011-06-25 22:09:31vstinnersetmessageid: <1309039771.74.0.357591759355.issue12410@psf.upfronthosting.co.za>
2011-06-25 22:09:31vstinnerlinkissue12410 messages
2011-06-25 22:09:30vstinnercreate