{"id":165037,"date":"2020-10-03T05:58:38","date_gmt":"2020-10-02T21:58:38","guid":{"rendered":"http:\/\/4563.org\/?p=165037"},"modified":"2020-10-03T05:58:38","modified_gmt":"2020-10-02T21:58:38","slug":"%e6%80%8e%e4%b9%88%e7%ae%80%e5%8d%95%e7%9a%84%e9%99%90%e5%88%b6%e4%b8%80%e4%b8%aa%e5%87%bd%e6%95%b0%e7%9a%84%e8%bf%90%e8%a1%8c%e6%97%b6%e9%97%b4%ef%bc%9f-try-in-n-seconds-%e8%b6%85%e6%97%b6%e5%b0%b1","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=165037","title":{"rendered":"\u600e\u4e48\u7b80\u5355\u7684\u9650\u5236\u4e00\u4e2a\u51fd\u6570\u7684\u8fd0\u884c\u65f6\u95f4\uff1f try (in n seconds) \u8d85\u65f6\u5c31 pass"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u600e\u4e48\u7b80\u5355\u7684\u9650\u5236\u4e00\u4e2a\u51fd\u6570\u7684\u8fd0\u884c\u65f6\u95f4\uff1f try (in n seconds) \u8d85\u65f6\u5c31 pass               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : miniyao <\/span>  <span><i><\/i> 2<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u7531\u4e8e\u5728\u4e00\u4e2a\u7ebf\u7a0b\u4e2d\u63a5\u5165\u4e86\u4e00\u4e2a\u7b2c\u4e09\u65b9\u670d\u52a1\uff0c\u8fd9\u4e2a\u8fdc\u7a0b\u670d\u52a1\u5e76\u4e0d\u662f\u5f88\u91cd\u8981\uff0c\u8fdc\u7a0b\u8c03\u7528\u7ebf\u8def\u548c\u8bf7\u6c42\u603b\u6709\u5931\u8d25\u7684\u53ef\u80fd\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u5c31\u60f3\u628a\u8fd9\u4e2a\u51fd\u6570\u653e\u5728 Try \u4e2d\u53bb\u8fd0\u884c\uff1a<\/p>\n<pre><code>try:      do_something()  except:      pass <\/code><\/pre>\n<p>\u7531\u4e8e\u6bcf\u6b21 do_something() \u4f1a\u963b\u585e\u5f53\u524d\u7ebf\u7a0b\uff0c\u6240\u4ee5\u60f3\u9650\u5236\u4e2a\u6700\u957f\u6267\u884c\u65f6\u95f4\uff0c\u8d85\u65f6\u76f4\u63a5 pass \u3002<\/p>\n<p>\u7528 eventlet \u6709\u70b9\u504f\u91cd\uff0c\u6709\u6ca1\u6709\u4ec0\u4e48\u6bd4\u8f83\u7b80\u5355\u7684\u5b9e\u73b0\u4f18\u96c5\u7684\u5b9e\u73b0\u65b9\u6cd5\uff1f<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>14<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3628189\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : imn1 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fdc\u7a0b\u6a21\u5757\u4e00\u822c\u90fd\u6709 timeout \u5f02\u5e38\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3628190\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Mitt <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5f00\u7ebf\u7a0b\u8d85\u65f6\u7136\u540e\u5f3a\u5236\u7ec8\u6b62\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3628191\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : kangsheng9527 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             python \u4e0d\u77e5\u9053\uff0cgo \u53ef\u4ee5\u4f7f\u7528 context \u5305\u53bb\u5904\u7406\u3002\u3002\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3628192\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : JeffGe <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u65b0\u5efa\u8fdb\u7a0b\u8d85\u65f6\u5c31 kill \u53ef\u884c\u5417                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3628193\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : dbow <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u79cd\u5f97\u7528\u534f\u7a0b\u8981\u641e\uff0c python3 \u91cc\u8fb9\u6709 async, await, \u524d\u63d0\u662f\u4f60\u4f7f\u7528\u7684\u5e93\u652f\u6301\u8fd9\u4e48\u64cd\u4f5c\uff0e                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3628194\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : infun <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8bd5\u8bd5 retrying \u5e93                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3628195\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ClericPy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7ebf\u7a0b\u5dee\u5c31\u5dee\u5728\u6ca1\u6cd5\u5916\u90e8\u5f3a\u5236\u505c\u6b62, \u6240\u4ee5\u8fd9\u79cd\u573a\u666f\u6211\u90fd\u662f\u534f\u7a0b\u8dd1\u7684, \u5916\u90e8\u8d85\u65f6\u76f4\u63a5\u53d1\u9001 cancel \u6307\u4ee4<\/p>\n<p>\u81f3\u4e8e\u8fdc\u7a0b\u8c03\u7528\u76f8\u5173\u7684, \u4e00\u822c\u4f1a\u6709\u8d85\u65f6\u63a7\u5236\u5427, \u5177\u4f53\u770b\u4f60 do \u4e86\u4ec0\u4e48 thing \u4e86                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3628196\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : MoYi123 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @contextmanager<br \/>def timeout_signal(second):<br \/>____signal.signal(signal.SIGALRM, raise_timeout)<br \/>____signal.alarm(second)<br \/>____try:<br \/>________yield<br \/>____finally:<br \/>________signal.signal(signal.SIGALRM, signal.SIG_IGN)<\/p>\n<p>def raise_timeout(_signum, _frame):<br \/>____raise TimeoutError<\/p>\n<p>def timeout(second):<br \/>____def _timeout(fun):<br \/>[email&#160;protected](fun)<br \/>________def _fun(*args, **kwargs):<br \/>____________with timeout_signal(second):<br \/>________________return fun(*args, **kwargs)<\/p>\n<p>________return _fun<\/p>\n<p>____return _timeout<\/p>\n<p>@timeout(1)<br \/>def f():<br \/>____pass<\/p>\n<p>\u6211\u5e73\u65f6\u7684\u7528\u811a\u672c\u91cc\u662f\u8fd9\u6837\u5199\u7684\uff0c\u6027\u80fd\u597d\u574f\u4e0d\u786e\u5b9a\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3628197\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : MiracleKagari <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             rxpy \u5e94\u8be5\u6709                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3628198\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : MiracleKagari <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @MiracleKagari \u521b\u5efa\u4e00\u4e2a\u54cd\u5e94\u5f0f\u5bf9\u8c61\uff0c\u7136\u540e\u627e\u4e00\u4e2a\u5408\u9002\u7684\u64cd\u4f5c\u7b26\uff0c\u7136\u540e&#8230;                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3628199\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : tkmiles <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f7f\u7528 future \u5440<br \/>\u4e00\u4e2a\u7ebf\u7a0b\u7ed3\u675f\u4e4b\u540e\u66f4\u65b0 future<br \/>\u53e6\u5916\u4e00\u4e2a\u7ebf\u7a0b\u5728 future \u4e0a\u7b49\u5f85, future \u4e0a\u53ef\u4ee5\u52a0 timeout \u7684<br \/>\u7136\u540e\u53e6\u5916\u4e00\u4e2a\u7ebf\u7a0b\u5728 timeout \u4e4b\u540e\u76f4\u63a5\u7ec8\u6b62\u5b50\u7ebf\u7a0b<\/p>\n<p>python \u7ec8\u6b62\u5b50\u7ebf\u7a0b\u6709\u70b9\u9650\u5236, \u53ea\u80fd\u53d1\u9001\u7ebf\u7a0b\u5f02\u6b65\u5f02\u5e38\u53bb\u7ec8\u6b62 python \u4ee3\u7801\u6267\u884c, \u5982\u679c\u4f60\u5361\u5728 C \u7ea7\u522b\u7684\u4ee3\u7801, \u90a3\u53ea\u80fd\u7b49\u5f85<br \/>\u56de\u8c03\u56de python \u4ee3\u7801\u7684\u65f6\u5019, \u5f02\u6b65\u5f02\u5e38\u624d\u80fd\u7ec8\u6b62\u7ebf\u7a0b<\/p>\n<p>\u5982\u679c\u4f60\u60f3\u7ec8\u6b62\u7ebf\u7a0b\u66f4\u4e25\u683c\u4e00\u70b9, \u6bd4\u5982\u7ec8\u6b62 C \u4ee3\u7801, \u90a3\u4e48\u53ea\u80fd\u6c42\u52a9\u4e8e\u7cfb\u7edf\u4e2d\u65ad\u4e86                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3628200\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : itskingname <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5982\u679c\u662f macOS \u548c Linux\uff0c\u6211\u5199\u8fc7\u4e00\u7bc7\u6587\u7ae0\u6765\u8bf4\u660e\uff1a https:\/\/mp.weixin.qq.com\/s\/PUcHuJMG5Mk2tWWzYeq2wQ                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3628201\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : l4ever <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             import multiprocessing as mp <br \/>def pool_funcs(func, args=(), kwds=None, timeout=1, default=None):<br \/> &#8220;&#8221;&#8221;<br \/> \u7ebf\u7a0b\u8d85\u65f6<br \/> @param func:<br \/> @param args:<br \/> @param kwds:<br \/> @param timeout:<br \/> @param default:<br \/> @return:<br \/> &#8220;&#8221;&#8221;<\/p>\n<p> pool = mp.Pool(processes=1)<br \/> result = pool.apply_async(func, args=args, kwds=kwds)<br \/> try:<br \/> val = result.get(timeout=timeout)<br \/> except mp.TimeoutError:<br \/> pool.terminate()<br \/> return default<br \/> else:<br \/> pool.close()<br \/> pool.join()<br \/> return val                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3628202\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : namelosw <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u4e2a\u548c\u505c\u673a\u95ee\u9898\u76f8\u5173\uff0c\u5982\u679c\u8bed\u8a00\u6ca1\u6709\u63d0\u4f9b\u7279\u6b8a\u7684\u673a\u5236\u7684\u8bdd\u4e00\u822c\u8981\u9760\u5b50\u8fdb\u7a0b+\u76d1\u62a4\u7684\u5f62\u5f0f\uff0c\u56e0\u4e3a\u505c\u673a\u662f\u6ca1\u6cd5\u672c\u5730\u6062\u590d\u7684\u3002\u50cf\u5927\u91cf\u5e94\u7528\u8fd9\u79cd\u6a21\u5f0f\u7684 Erlang\uff0c\u4e5f\u662f\u5c3d\u91cf\u901a\u8fc7\u628a\u8fdb\u7a0b\u505a\u5f97\u8d85\u7ea7\u8f7b\u91cf\u5316\uff0c\u7136\u540e\u7528\u540c\u6837\u7684\u65b9\u5f0f\u5b9e\u73b0\u7684\u3002<\/p>\n<p>\u8fd8\u6709\u4e00\u4e9b\u5f62\u5f0f\u5c31\u662f\u81ea\u5df1\u5199\u4e00\u4e2a\u7b80\u5355\u7684\u7c7b\u4f3c\u89e3\u91ca\u5668\u7684\u4e1c\u897f\uff0c\u4f60\u91cd\u65b0\u53d1\u660e\u5e76\u5d4c\u5165\u4e00\u4e2a\u8bed\u8a00\uff0c\u8fd9\u4e2a\u8bed\u8a00\u7684\u89e3\u91ca\u5f52\u4f60\u7ba1\uff0c\u5c31\u53ef\u4ee5\u5728\u6bcf\u4e2a\u6c42\u503c\u5468\u671f\u90fd\u68c0\u67e5\u4e00\u6b21 timeout \u3002\u7c7b\u4f3c\u7684\u4f8b\u5b50\u6bd4\u8f83\u50cf React fiber \u2014\u2014 \u4e0d\u8fc7 fiber \u53ea\u80fd\u7ba1 React \u6e32\u67d3\uff0c\u800c\u4e0d\u80fd\u7ba1 JavaScript \u6267\u884c\uff0c\u4e5f\u5c31\u662f\u8bf4\u8fd9\u79cd timeout \u5c31 kill \u6389\u7684\u673a\u5236\u53ea\u80fd\u5bf9 React \u81ea\u5df1\u7684 DSL \uff08 JSX \u4ee5\u53ca Element \u7684 Rendering \uff09\u6210\u7acb\uff0c\u800c\u5bf9 JavaScript \u6ca1\u6709\u666e\u9002\u6027\uff0c\u9664\u975e\u91cd\u65b0\u5b9e\u73b0\u4e00\u904d JavaScript\uff0c\u6216\u8005\u542f\u53e6\u5916\u4e00\u4e2a JavaScript \u8fdb\u7a0b\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u600e\u4e48\u7b80\u5355\u7684\u9650\u5236\u4e00\u4e2a\u51fd\u6570\u7684\u8fd0\u884c\u65f6\u95f4\uff1f&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/165037"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=165037"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/165037\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=165037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=165037"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=165037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}