跨平台超时装饰 [英] Cross-platform time out decorator

查看:81
本文介绍了跨平台超时装饰的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用这个漂亮的超时装饰器:
http://aspn.activestate.com/ASPN/Coo.../Recipe/307871

问题是因为它依赖于sigalarm,所以它不会在

windows下运行。有谁知道如何做跨平台版本?


非常感谢!


joel

I''ve been using this nice timing out decorator :
http://aspn.activestate.com/ASPN/Coo.../Recipe/307871 . The
problem is that since it relies on sigalarm, it doesn''t work under
windows. Would anyone know how to do a cross-platform version?

Thanks a lot!

joel

推荐答案

Joel写道:
Joel wrote:

我一直在使用这个漂亮的超时装饰器:
http://aspn.activestate.com/ASPN/Coo ... /食谱/ 307871

问题是因为它依赖于sigalarm,所以它不会在

windows下运行。有谁知道如何做跨平台版本?
I''ve been using this nice timing out decorator :
http://aspn.activestate.com/ASPN/Coo.../Recipe/307871 . The
problem is that since it relies on sigalarm, it doesn''t work under
windows. Would anyone know how to do a cross-platform version?



我不认为你会找到任何直截了当的东西。 AFAIK,

在Windows方面没有什么东西直接相当于* nix中信号业务的
。当然,你可以用计时器,线程和事件等来搞乱
。但它远不是信号模块为您提供的内置工具。


TJG

I don''t think you''re going to find anything straightforward. AFAIK,
there''s nothing on the Windows side of things which is directly
equivalent to the signals business in *nix. Sure, you can mess around
with timers and threads and events and so on. But it''s far from being
the built-in tool which the signal module gives you.

TJG


9月26日上午5:21,Joel< joel.schae ... @ gmail.comwrote:
On Sep 26, 5:21 am, Joel <joel.schae...@gmail.comwrote:

我去过使用这个漂亮的超时装饰: http://aspn.activestate .COM / ASPN /库尔... /方/ 307871

问题是因为它依赖于sigalarm,所以它不会在

windows下运行。有谁知道如何做跨平台版本?


非常感谢!


joel
I''ve been using this nice timing out decorator :http://aspn.activestate.com/ASPN/Coo.../Recipe/307871. The
problem is that since it relies on sigalarm, it doesn''t work under
windows. Would anyone know how to do a cross-platform version?

Thanks a lot!

joel



您可以使用timeit模块。

http://docs.python.org/lib/module-timeit.html


有些人喜欢使用hotshot:<

http ://www.onlamp.com/pub/a/python/2...profiling.html

我怀疑这是你在找什么,但也许它会给你一个朝着正确方向推进的



迈克

You might be able to use the timeit module.

http://docs.python.org/lib/module-timeit.html

Some people like to use hotshot:

http://www.onlamp.com/pub/a/python/2...profiling.html

I doubt this is what you''re looking for, but maybe it''ll give you a
push in the right direction.

Mike


9月26日下午12:21,Joel< joel.schae ... @ gmail.comwrote:
On Sep 26, 12:21 pm, Joel <joel.schae...@gmail.comwrote:

我一直在使用这个漂亮的超时装饰: http://aspn.activestate.com/ASPN/Coo.../Recipe/307871

问题是因为它依赖于sigalarm,所以它不会在

windows下运行。有谁知道如何做跨平台版本?


非常感谢!


joel
I''ve been using this nice timing out decorator :http://aspn.activestate.com/ASPN/Coo.../Recipe/307871. The
problem is that since it relies on sigalarm, it doesn''t work under
windows. Would anyone know how to do a cross-platform version?

Thanks a lot!

joel



我找到了解决方案: http: //aspn.activestate.com/ASPN/Coo.../Recipe/440569

描述了基于线程的解决方案。我测试了它并且完美地工作了



I found the solution : http://aspn.activestate.com/ASPN/Coo.../Recipe/440569
describes a solution based on threads. I tested it and it works
perfectly.


这篇关于跨平台超时装饰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆