{"id":3488,"date":"2019-03-12T15:45:42","date_gmt":"2019-03-12T07:45:42","guid":{"rendered":"https:\/\/www.yewen.us\/blog\/?p=3488"},"modified":"2019-03-12T15:45:42","modified_gmt":"2019-03-12T07:45:42","slug":"python-decorator-conflict-to-gevent","status":"publish","type":"post","link":"https:\/\/www.yewen.us\/blog\/2019\/03\/python-decorator-conflict-to-gevent\/","title":{"rendered":"Python decorator \u5e93\u548c gevent \u51b2\u7a81\u7684\u60c5\u51b5"},"content":{"rendered":"<p>\u53bb\u5e74\u5199\u4e86\u4e24\u7bc7\u5206\u6790 decorator \u7684 blog:<\/p>\n<ul>\n<li><a href=\"https:\/\/www.yewen.us\/blog\/2018\/05\/get-args-of-origin-function-in-python-decorator-chain\/\" rel=\"noopener noreferrer\" target=\"_blank\">Python \u591a\u5c42 decorator \u5185\u83b7\u53d6\u539f\u59cb\u51fd\u6570\u53c2\u6570\u5b57\u5178<\/a><\/li>\n<li><a href=\"https:\/\/www.yewen.us\/blog\/2018\/09\/python-decorator-lib\/\" rel=\"noopener noreferrer\" target=\"_blank\">Python decorator \u5e93<\/a><\/li>\n<\/ul>\n<p>\u5728\u7ebf\u4e0a\u9879\u76ee\u91cc\u4e00\u76f4\u4e5f\u6ca1\u6709\u7528 pypi \u7684 decorator \u5e93\u53bb\u66ff\u6362\u81ea\u5df1\u7684\u5b9e\u73b0\uff0c\u6700\u8fd1\u66ff\u6362\u540e\u649e\u4e0a\u4e86\u4e00\u4e9b\u95ee\u9898\uff0c\u6574\u4e2a\u95ee\u9898\u8ffd\u67e5\u8fc7\u7a0b\u4e5f\u5404\u79cd\u8270\u8f9b\uff0c\u8bb0\u5f55\u4e00\u4e0b<\/p>\n<p>\u6211\u4eec\u7ebf\u4e0a\u7528\u7684 flask 0.11.1 + celery 3.1.25 + gevent 1.2.2 \u5728\u8dd1\u4efb\u52a1\u961f\u5217\uff0cbroken \u7528\u7684\u963f\u91cc\u4e91 redis 2.8\uff0c\u67d0\u4e2a\u5468\u672b\u7a81\u7136\u53d1\u73b0 worker \u5de5\u4f5c\u4e0d\u6b63\u5e38\uff0c\u6709\u5927\u91cf\u7684 db \u8fde\u63a5\u62a5\u9519\uff0c\u5728\u7b80\u77ed\u6392\u67e5\u540e\u6ca1\u627e\u5230\u539f\u56e0\uff0c\u91cd\u542f\u6574\u4e2a\u670d\u52a1\uff0c\u6682\u65f6\u8df3\u8fc7\u8fd9\u4e2a\u95ee\u9898\uff0c\u5176\u5b9e\u540e\u9762\u8fd8\u5728\u6709\u5176\u4ed6\u9519\u8bef\uff0c\u4f46\u4e5f\u6ca1\u6709\u89e3\u51b3\u601d\u8def<\/p>\n<p>\u7b49\u5468\u4e00\u5230\u516c\u53f8\uff0c\u56e2\u961f\u7684\u4eba\u5bf9\u6bd4\u4e86\u4e0b\u95ee\u9898\u73b0\u573a\u548c\u601d\u8def\uff0c\u53ea\u80fd\u53d1\u73b0\u662f celery worker \u4f1a\u83ab\u540d\u5361\u6b7b\uff0c\u8dd1\u5230\u6211\u4eec\u7684 k8s \u96c6\u7fa4\u4e0a\u770b\uff0c\u5bf9\u5e94\u7684 pod \u662f running\uff0c\u4f46\u662f flower \u4e0a\u770b\u76d1\u63a7\u662f offline\uff0c\u76f4\u63a5\u5207\u8fdb pod \u770b\u65e5\u5fd7\uff0c\u597d\u51e0\u4e2a\u6700\u540e\u90fd\u65ad\u5728 requests \u53d1\u8bf7\u6c42\u51fa\u53bb\u7684\u5730\u65b9\uff0cN \u8138\u61f5\u903c\uff0c\u6211\u4eec\u53c8\u6ca1\u5347\u7ea7\u7cfb\u7edf\u53c8\u6ca1\u52a8\u4f9d\u8d56\uff0c\u600e\u4e48\u5c31\u4f1a\u5192\u51fa\u6765\u8fd9\u4e2a\u95ee\u9898<\/p>\n<p>\u65e2\u7136\u6700\u540e\u6b7b\u5728 requests \u90a3\uff0c\u867d\u7136\u770b\u540e\u9762\u7684 Changelog \u6ca1\u53d1\u73b0\u6709\u8ddf\u6211\u4eec\u76f4\u63a5\u4e60\u60ef\u7684\uff0c\u4f46\u8fd8\u662f\u5148\u628a requests \u7248\u672c\u4ece 2.19.0 \u5347\u5230 2.21.0\uff0c\u5e76\u628a\u4f9d\u8d56\u7684\u5e93\u4e5f\u540c\u6b65\u5347\u7ea7\u3002\u7136\u800c\u5e76\u6ca1\u6709\u89e3\u51b3\u95ee\u9898\uff0c\u8fd8\u662f\u4e00\u6837\u7684\u6b7b\uff0c\u8fd8\u662f\u4e00\u6837\u7684\u9519<\/p>\n<p>\u540e\u9762\u591a\u770b\u4e86\u51e0\u4e2a\u95ee\u9898\u73b0\u573a\uff0c\u53ea\u80fd\u534f\u52a9\u5b9a\u4f4d\u8fd8\u53ef\u80fd\u4f1a\u5361\u6b7b\u5728 db \u8bfb\u5199\u7684\u5730\u65b9\uff0c\u8fd9\u4e2a\u65f6\u5019\u5f00\u59cb\u6000\u7591 gevent\uff0c\u56e0\u4e3a\u8fd9\u8d27\u5e2e\u5fd9\u505a\u4e86 IO \u5f02\u6b65\u4f18\u5316\uff0c\u5f3a\u884c\u534f\u7a0b\u5316\uff0c\u800c\u4e14\u8fd9\u4e2a\u7248\u672c\u4e5f\u6709\u70b9\u8001\uff0c\u671f\u95f4\u770b\u4e5f\u6709\u4e00\u4e9b\u53ef\u80fd\u76f8\u5173\u7684 Issue\uff0c\u5347\u7ea7 1.4.0 \u540e\u53d1\u73b0\u670d\u52a1\u8d77\u4e0d\u6765\uff0c\u67e5\u4e86\u4e0b\u770b\u9700\u8981\u628a celery \u5347\u7ea7\u5230 4.x\uff0c\u4f46 4.x \u7684 celery \u53c2\u6570\u5e8f\u5217\u5316\u4ece pickle \u6539\u6210 json\uff0c\u8fd8\u8981\u6539\u633a\u591a\u4ee3\u7801\u7684\uff0c\u53ea\u80fd\u5148\u6401\u7f6e<\/p>\n<p>\u540e\u9762\u8fd8\u67e5\u4e86\u4e0b celery \u7684\u7248\u672c\u95ee\u9898\uff0c\u6211\u4eec\u7528\u7684 3.x \u662f\u6709\u70b9\u8001\u4e86\uff0c\u4f46 4.x \u90a3\u4e2a\u53c2\u6570\u7ed3\u6784\u8be5\u52a8\u90a3\u4e2a\u6709\u5927\u6240\u4ee5\u4e00\u76f4\u6ca1\u52a8\uff0c\u53e6\u5916\u4e5f\u67e5\u7528 redis \u505a broken \u7684\u9505\uff0c\u6ca1\u6709\u4efb\u4f55\u6709\u6548\u7684\u76f8\u5173\u4fe1\u606f<\/p>\n<p>\u51fa\u95ee\u9898\u524d\u6211\u5728\u4ee3\u7801\u91cc\u66ff\u6362\u4e86\u4e00\u7248 lock \u7684\u5b9e\u73b0\uff0c\u4ee5\u53ca lock_decorator \u7684\u5b9e\u73b0\uff0c\u4f46\u662f\u5f80\u8fd9\u8fb9\u6000\u7591\u4e5f\u4e0d\u5bf9\uff0c\u56e0\u4e3a\u6709\u7684\u51fa\u9519\u7684\u5730\u65b9\u5e76\u6ca1\u6709\u7528\u5230\u9501\uff0c\u800c\u4e14\u770b\u65e5\u5fd7\u548c\u62a5\u9519\u4e5f\u8ddf\u9501\u6ca1\u6709\u5173\u7cfb<\/p>\n<p>\u7b49\u8fc7\u4e86\u4e00\u5468\uff0c\u7b2c\u4e8c\u4e2a\u5468\u672b\u7684\u65f6\u5019\u5f00\u8111\u6d1e\u8bf4\u597d\u50cf\u73b0\u5728\u6709\u95ee\u9898\u7684\u65b9\u6cd5\u90fd\u6709\u4fee\u9970\u5668\u5305\u7740\uff0c\u800c\u4e14\u8fd9\u4e9b\u4fee\u9970\u5668\u90fd\u7528\u4e86 decorator \u5e93\uff0c\u4e5f\u8bb8\u8fd9\u91cc\u53ef\u80fd\u6709\u95ee\u9898\uff1f\u6211\u4eec\u7684 decorator \u7528\u7684\u662f 4.3.0\uff0c\u6700\u65b0\u7684\u7248\u672c\u662f 4.3.2\uff0c\u5927\u81f4\u770b\u4e86\u4e0b Changelog\uff0c\u4f3c\u4e4e\u63d0\u5230\u6709\u4fee\u590d\u534f\u7a0b\u95ee\u9898\uff0c\u4f46\u662f\u662f python 3.5 \u7684\uff0c\u4e0d\u8fc7\u53cd\u6b63\u4e0d\u7528\u6539\u4ee3\u7801\uff0c\u5148\u5347\u4e86\u518d\u8bf4<\/p>\n<p>\u5347\u5b8c\u540e\u95ee\u9898\u771f\u7684\u6d88\u5931\u4e86\uff0c\u90a3\u4e48\u5c31\u6765\u770b\u770b\u5230\u5e95\u54ea\u91cc\u53ef\u80fd\u6709\u95ee\u9898\u5427\u3002\u5bf9\u6bd4\u671f\u95f4\u7684\u53d8\u66f4\u8bb0\u5f55 <a href=\"https:\/\/github.com\/micheles\/decorator\/compare\/4.3.0...4.3.2\" rel=\"noopener noreferrer\" target=\"_blank\">https:\/\/github.com\/micheles\/decorator\/compare\/4.3.0&#8230;4.3.2<\/a>\uff0c\u9664\u4e86\u4e00\u4e9b\u6587\u6863\u53d8\u5316\u548c\u5bf9 py3.5 \u7684\u534f\u7a0b\u4fee\u590d\uff0c\u6bd4\u8f83\u503c\u5f97\u6000\u7591\u7684\u662f <a href=\"https:\/\/github.com\/micheles\/decorator\/commit\/eb890d98739196b83f1ecb5cb7bcfe9739a9502c\" rel=\"noopener noreferrer\" target=\"_blank\">https:\/\/github.com\/micheles\/decorator\/commit\/eb890d98739196b83f1ecb5cb7bcfe9739a9502c<\/a> \u8fd9\u4e2a\u63d0\u4ea4\uff0cdecorator \u7684\u539f\u7406\u662f\u5728\u5185\u5b58\u91cc\u65b0\u5efa\u4e00\u4e2a\u865a\u62df\u6587\u4ef6\uff0c\u628a\u8981\u4fee\u9970\u7684\u65b9\u6cd5\u7684\u76f8\u5173\u5c5e\u6027\u5199\u5230\u8fd9\u4e2a\u865a\u62df\u6587\u4ef6\u91cc\uff0c\u7136\u540e\u901a\u8fc7\u865a\u62df\u6587\u4ef6\u91cc\u7684\u540c\u540d\u65b9\u6cd5\u8c03\u88c5\u9970\u5668\u903b\u8f91\uff0c\u88c5\u9970\u5668\u65b9\u6cd5\u91cc\u518d\u53bb\u8c03\u5230\u6700\u7ec8\u7684\u65b9\u6cd5\uff0c\u800c\u8fd9\u4e2a\u865a\u62df\u6587\u4ef6\u5982\u679c\u53ea\u7528 <code>itertools.count()<\/code>\uff0c\u5728 gevent \u7684\u534f\u7a0b\u8c03\u5ea6\u4e0b\u53ef\u80fd\u4f1a\u91cd\u540d\uff0c\u7136\u540e\u6574\u4e2a\u4ee3\u7801\u4f53\u7cfb\u5c31\u5d29\u4e86<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u53bb\u5e74\u5199\u4e86\u4e24\u7bc7\u5206\u6790 decorator \u7684 blog: Python \u591a\u5c42 decorator \u5185\u83b7\u53d6\u539f\u59cb\u51fd\u6570\u53c2 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[7],"tags":[665,685,127],"class_list":["post-3488","post","type-post","status-publish","format-standard","hentry","category-tech-notes","tag-decorator","tag-gevent","tag-python"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4aR5e-Ug","_links":{"self":[{"href":"https:\/\/www.yewen.us\/blog\/wp-json\/wp\/v2\/posts\/3488","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yewen.us\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yewen.us\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yewen.us\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yewen.us\/blog\/wp-json\/wp\/v2\/comments?post=3488"}],"version-history":[{"count":3,"href":"https:\/\/www.yewen.us\/blog\/wp-json\/wp\/v2\/posts\/3488\/revisions"}],"predecessor-version":[{"id":3496,"href":"https:\/\/www.yewen.us\/blog\/wp-json\/wp\/v2\/posts\/3488\/revisions\/3496"}],"wp:attachment":[{"href":"https:\/\/www.yewen.us\/blog\/wp-json\/wp\/v2\/media?parent=3488"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yewen.us\/blog\/wp-json\/wp\/v2\/categories?post=3488"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yewen.us\/blog\/wp-json\/wp\/v2\/tags?post=3488"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}