{"id":1135287,"date":"2025-01-08T21:23:46","date_gmt":"2025-01-08T13:23:46","guid":{"rendered":""},"modified":"2025-01-08T21:23:48","modified_gmt":"2025-01-08T13:23:48","slug":"python%e5%a6%82%e4%bd%95%e5%b0%86%e5%8f%98%e9%87%8f%e8%ae%be%e7%bd%ae%e4%b8%ba%e5%85%a8%e5%b1%80%e5%8f%98%e9%87%8f","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1135287.html","title":{"rendered":"python\u5982\u4f55\u5c06\u53d8\u91cf\u8bbe\u7f6e\u4e3a\u5168\u5c40\u53d8\u91cf"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25104004\/f4bc2398-b120-4eb4-899a-9bdd18197689.webp\" alt=\"python\u5982\u4f55\u5c06\u53d8\u91cf\u8bbe\u7f6e\u4e3a\u5168\u5c40\u53d8\u91cf\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u5c06\u53d8\u91cf\u8bbe\u7f6e\u4e3a\u5168\u5c40\u53d8\u91cf\u7684\u65b9\u6cd5\u4e3b\u8981\u6709\u4ee5\u4e0b\u51e0\u70b9\uff1a\u4f7f\u7528<code>global<\/code>\u5173\u952e\u5b57\u3001\u5c06\u53d8\u91cf\u5b9a\u4e49\u5728\u51fd\u6570\u5916\u90e8\u3001\u4f7f\u7528\u7c7b\u548c\u5bf9\u8c61\u3002<\/strong>\u5176\u4e2d\uff0c\u4f7f\u7528<code>global<\/code>\u5173\u952e\u5b57\u662f\u5728\u51fd\u6570\u5185\u90e8\u58f0\u660e\u5168\u5c40\u53d8\u91cf\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u8ba8\u8bba\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u5e76\u63d0\u4f9b\u793a\u4f8b\u4ee3\u7801\u4ee5\u4fbf\u66f4\u597d\u5730\u7406\u89e3\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528<code>global<\/code>\u5173\u952e\u5b57<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u5982\u679c\u60f3\u5728\u51fd\u6570\u5185\u90e8\u4fee\u6539\u5168\u5c40\u53d8\u91cf\u7684\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528<code>global<\/code>\u5173\u952e\u5b57\u3002\u8fd9\u4e2a\u5173\u952e\u5b57\u544a\u8bc9Python\u89e3\u91ca\u5668\uff0c\u5728\u51fd\u6570\u5185\u90e8\u5f15\u7528\u7684\u53d8\u91cf\u662f\u5168\u5c40\u53d8\u91cf\uff0c\u800c\u4e0d\u662f\u5c40\u90e8\u53d8\u91cf\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">x = 10<\/p>\n<p>def modify_global():<\/p>\n<p>    global x<\/p>\n<p>    x = 20<\/p>\n<p>modify_global()<\/p>\n<p>print(x)  # \u8f93\u51fa20<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u53d8\u91cf<code>x<\/code>\u5728\u51fd\u6570<code>modify_global<\/code>\u5185\u90e8\u88ab\u4fee\u6539\uff0c\u56e0\u4e3a\u6211\u4eec\u4f7f\u7528\u4e86<code>global<\/code>\u5173\u952e\u5b57\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u5c06\u53d8\u91cf\u5b9a\u4e49\u5728\u51fd\u6570\u5916\u90e8<\/h3>\n<\/p>\n<p><p>\u53e6\u4e00\u79cd\u65b9\u6cd5\u662f\u76f4\u63a5\u5c06\u53d8\u91cf\u5b9a\u4e49\u5728\u51fd\u6570\u5916\u90e8\uff0c\u8fd9\u6837\u8be5\u53d8\u91cf\u5c31\u662f\u5168\u5c40\u53d8\u91cf\uff0c\u53ef\u4ee5\u5728\u4efb\u4f55\u51fd\u6570\u5185\u90e8\u8fdb\u884c\u8bbf\u95ee\u548c\u4fee\u6539\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">y = 30<\/p>\n<p>def read_global():<\/p>\n<p>    print(y)<\/p>\n<p>def modify_global():<\/p>\n<p>    global y<\/p>\n<p>    y = 40<\/p>\n<p>read_global()  # \u8f93\u51fa30<\/p>\n<p>modify_global()<\/p>\n<p>read_global()  # \u8f93\u51fa40<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u53d8\u91cf<code>y<\/code>\u5728\u51fd\u6570\u5916\u90e8\u5b9a\u4e49\uff0c\u56e0\u6b64\u5b83\u5728\u4efb\u4f55\u51fd\u6570\u5185\u90e8\u90fd\u662f\u5168\u5c40\u53d8\u91cf\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u7c7b\u548c\u5bf9\u8c61<\/h3>\n<\/p>\n<p><p>\u7b2c\u4e09\u79cd\u65b9\u6cd5\u662f\u901a\u8fc7\u7c7b\u548c\u5bf9\u8c61\u6765\u5b9e\u73b0\u5168\u5c40\u53d8\u91cf\u3002\u5728\u8fd9\u79cd\u65b9\u6cd5\u4e2d\uff0c\u53ef\u4ee5\u5c06\u53d8\u91cf\u5b9a\u4e49\u4e3a\u7c7b\u7684\u5c5e\u6027\uff0c\u8fd9\u6837\u5b83\u5c31\u53ef\u4ee5\u5728\u7c7b\u7684\u4efb\u4f55\u65b9\u6cd5\u4e2d\u8bbf\u95ee\u548c\u4fee\u6539\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">class GlobalVariables:<\/p>\n<p>    def __init__(self):<\/p>\n<p>        self.z = 50<\/p>\n<p>    def modify_global(self):<\/p>\n<p>        self.z = 60<\/p>\n<p>    def read_global(self):<\/p>\n<p>        print(self.z)<\/p>\n<p>global_vars = GlobalVariables()<\/p>\n<p>global_vars.read_global()  # \u8f93\u51fa50<\/p>\n<p>global_vars.modify_global()<\/p>\n<p>global_vars.read_global()  # \u8f93\u51fa60<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u53d8\u91cf<code>z<\/code>\u4f5c\u4e3a\u7c7b<code>GlobalVariables<\/code>\u7684\u5c5e\u6027\uff0c\u53ef\u4ee5\u5728\u7c7b\u7684\u4efb\u4f55\u65b9\u6cd5\u4e2d\u8fdb\u884c\u8bbf\u95ee\u548c\u4fee\u6539\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\u7684\u6ce8\u610f\u4e8b\u9879<\/h3>\n<\/p>\n<p><p>\u5c3d\u7ba1\u5168\u5c40\u53d8\u91cf\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u975e\u5e38\u6709\u7528\uff0c\u4f46\u6ee5\u7528\u5168\u5c40\u53d8\u91cf\u53ef\u80fd\u4f1a\u5bfc\u81f4\u4ee3\u7801\u96be\u4ee5\u7ef4\u62a4\u548c\u8c03\u8bd5\u3002\u56e0\u6b64\uff0c\u5728\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\u65f6\uff0c\u5e94\u8be5\u9075\u5faa\u4ee5\u4e0b\u51e0\u70b9\u5efa\u8bae\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u907f\u514d\u8fc7\u5ea6\u4f7f\u7528\u5168\u5c40\u53d8\u91cf<\/strong>\uff1a\u5168\u5c40\u53d8\u91cf\u7684\u4f5c\u7528\u8303\u56f4\u5f88\u5e7f\uff0c\u5982\u679c\u8fc7\u5ea6\u4f7f\u7528\uff0c\u5bb9\u6613\u5bfc\u81f4\u53d8\u91cf\u547d\u540d\u51b2\u7a81\u548c\u4e0d\u53ef\u9884\u89c1\u7684\u884c\u4e3a\u3002<\/li>\n<li><strong>\u4f7f\u7528\u660e\u786e\u7684\u547d\u540d<\/strong>\uff1a\u4e3a\u5168\u5c40\u53d8\u91cf\u4f7f\u7528\u660e\u786e\u4e14\u552f\u4e00\u7684\u547d\u540d\uff0c\u4ee5\u907f\u514d\u4e0e\u5c40\u90e8\u53d8\u91cf\u6216\u5176\u4ed6\u5168\u5c40\u53d8\u91cf\u6df7\u6dc6\u3002<\/li>\n<li><strong>\u9650\u5236\u5168\u5c40\u53d8\u91cf\u7684\u4f7f\u7528\u8303\u56f4<\/strong>\uff1a\u5c3d\u53ef\u80fd\u5c06\u5168\u5c40\u53d8\u91cf\u7684\u4f7f\u7528\u9650\u5236\u5728\u5fc5\u8981\u7684\u8303\u56f4\u5185\uff0c\u4ee5\u51cf\u5c11\u5bf9\u4ee3\u7801\u7684\u5f71\u54cd\u3002<\/li>\n<\/ol>\n<p><h3>\u4e94\u3001\u5168\u5c40\u53d8\u91cf\u7684\u5b9e\u9645\u5e94\u7528\u573a\u666f<\/h3>\n<\/p>\n<p><p>\u5168\u5c40\u53d8\u91cf\u5728\u67d0\u4e9b\u7279\u5b9a\u573a\u666f\u4e0b\u975e\u5e38\u6709\u7528\uff0c\u4e0b\u9762\u6211\u4eec\u5217\u4e3e\u51e0\u4e2a\u5e38\u89c1\u7684\u5b9e\u9645\u5e94\u7528\u573a\u666f\uff1a<\/p>\n<\/p>\n<p><h4>1. \u914d\u7f6e\u548c\u8bbe\u7f6e<\/h4>\n<\/p>\n<p><p>\u5728\u5927\u578b\u9879\u76ee\u4e2d\uff0c\u901a\u5e38\u9700\u8981\u5b9a\u4e49\u4e00\u4e9b\u5168\u5c40\u914d\u7f6e\u548c\u8bbe\u7f6e\uff0c\u8fd9\u4e9b\u914d\u7f6e\u548c\u8bbe\u7f6e\u53ef\u4ee5\u5728\u9879\u76ee\u7684\u4efb\u4f55\u5730\u65b9\u8bbf\u95ee\u548c\u4fee\u6539\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">config = {<\/p>\n<p>    &quot;host&quot;: &quot;localhost&quot;,<\/p>\n<p>    &quot;port&quot;: 8080,<\/p>\n<p>    &quot;debug&quot;: True<\/p>\n<p>}<\/p>\n<p>def read_config():<\/p>\n<p>    print(config)<\/p>\n<p>def modify_config():<\/p>\n<p>    global config<\/p>\n<p>    config[&quot;debug&quot;] = False<\/p>\n<p>read_config()  # \u8f93\u51fa{&#39;host&#39;: &#39;localhost&#39;, &#39;port&#39;: 8080, &#39;debug&#39;: True}<\/p>\n<p>modify_config()<\/p>\n<p>read_config()  # \u8f93\u51fa{&#39;host&#39;: &#39;localhost&#39;, &#39;port&#39;: 8080, &#39;debug&#39;: False}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u7f13\u5b58<\/h4>\n<\/p>\n<p><p>\u5728\u9700\u8981\u9891\u7e41\u8bbf\u95ee\u67d0\u4e9b\u6570\u636e\u7684\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\u4f5c\u4e3a\u7f13\u5b58\uff0c\u4ee5\u63d0\u9ad8\u8bbf\u95ee\u901f\u5ea6\u548c\u6548\u7387\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">cache = {}<\/p>\n<p>def fetch_data(key):<\/p>\n<p>    if key in cache:<\/p>\n<p>        return cache[key]<\/p>\n<p>    else:<\/p>\n<p>        data = &quot;some data&quot;  # \u6a21\u62df\u6570\u636e\u83b7\u53d6\u8fc7\u7a0b<\/p>\n<p>        cache[key] = data<\/p>\n<p>        return data<\/p>\n<p>print(fetch_data(&quot;key1&quot;))  # \u8f93\u51fa&#39;some data&#39;<\/p>\n<p>print(fetch_data(&quot;key1&quot;))  # \u8f93\u51fa&#39;some data&#39;\uff08\u4ece\u7f13\u5b58\u4e2d\u83b7\u53d6\uff09<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3. \u8ba1\u6570\u5668<\/h4>\n<\/p>\n<p><p>\u5168\u5c40\u53d8\u91cf\u8fd8\u53ef\u4ee5\u7528\u4e8e\u5b9e\u73b0\u8ba1\u6570\u5668\uff0c\u4f8b\u5982\u8bb0\u5f55\u51fd\u6570\u8c03\u7528\u6b21\u6570\u7b49\u3002<\/p>\n<\/p>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">counter = 0<\/p>\n<p>def increment_counter():<\/p>\n<p>    global counter<\/p>\n<p>    counter += 1<\/p>\n<p>increment_counter()<\/p>\n<p>increment_counter()<\/p>\n<p>print(counter)  # \u8f93\u51fa2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u5168\u5c40\u53d8\u91cf\u4e0e\u7ebf\u7a0b\u5b89\u5168<\/h3>\n<\/p>\n<p><p>\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e2d\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\u65f6\uff0c\u9700\u8981\u7279\u522b\u6ce8\u610f\u7ebf\u7a0b\u5b89\u5168\u95ee\u9898\u3002\u7531\u4e8e\u591a\u4e2a\u7ebf\u7a0b\u53ef\u80fd\u540c\u65f6\u8bbf\u95ee\u548c\u4fee\u6539\u5168\u5c40\u53d8\u91cf\uff0c\u53ef\u80fd\u5bfc\u81f4\u6570\u636e\u4e0d\u4e00\u81f4\u548c\u7ade\u6001\u6761\u4ef6\u3002<\/p>\n<\/p>\n<p><h4>\u89e3\u51b3\u65b9\u6848\uff1a<\/h4>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528\u7ebf\u7a0b\u9501<\/strong>\uff1a\u53ef\u4ee5\u4f7f\u7528<code>threading<\/code>\u6a21\u5757\u4e2d\u7684<code>Lock<\/code>\u5bf9\u8c61\u6765\u786e\u4fdd\u7ebf\u7a0b\u5b89\u5168\u3002<\/li>\n<\/ol>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import threading<\/p>\n<p>counter = 0<\/p>\n<p>lock = threading.Lock()<\/p>\n<p>def increment_counter():<\/p>\n<p>    global counter<\/p>\n<p>    with lock:<\/p>\n<p>        counter += 1<\/p>\n<p>threads = []<\/p>\n<p>for _ in range(10):<\/p>\n<p>    t = threading.Thread(target=increment_counter)<\/p>\n<p>    t.start()<\/p>\n<p>    threads.append(t)<\/p>\n<p>for t in threads:<\/p>\n<p>    t.join()<\/p>\n<p>print(counter)  # \u8f93\u51fa10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4f7f\u7528\u7ebf\u7a0b\u5c40\u90e8\u5b58\u50a8<\/strong>\uff1a\u53ef\u4ee5\u4f7f\u7528<code>threading<\/code>\u6a21\u5757\u4e2d\u7684<code>local<\/code>\u5bf9\u8c61\u4e3a\u6bcf\u4e2a\u7ebf\u7a0b\u5b58\u50a8\u72ec\u7acb\u7684\u53d8\u91cf\u3002<\/li>\n<\/ol>\n<p><h4>\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import threading<\/p>\n<p>local_data = threading.local()<\/p>\n<p>def process_data():<\/p>\n<p>    local_data.value = 0<\/p>\n<p>    for _ in range(1000):<\/p>\n<p>        local_data.value += 1<\/p>\n<p>    print(local_data.value)<\/p>\n<p>threads = []<\/p>\n<p>for _ in range(10):<\/p>\n<p>    t = threading.Thread(target=process_data)<\/p>\n<p>    t.start()<\/p>\n<p>    threads.append(t)<\/p>\n<p>for t in threads:<\/p>\n<p>    t.join()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e03\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u5c06\u53d8\u91cf\u8bbe\u7f6e\u4e3a\u5168\u5c40\u53d8\u91cf\u7684\u65b9\u6cd5\u4e3b\u8981\u6709\u4f7f\u7528<code>global<\/code>\u5173\u952e\u5b57\u3001\u5c06\u53d8\u91cf\u5b9a\u4e49\u5728\u51fd\u6570\u5916\u90e8\u3001\u4f7f\u7528\u7c7b\u548c\u5bf9\u8c61\u3002\u867d\u7136\u5168\u5c40\u53d8\u91cf\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u975e\u5e38\u6709\u7528\uff0c\u4f46\u6ee5\u7528\u5168\u5c40\u53d8\u91cf\u53ef\u80fd\u4f1a\u5bfc\u81f4\u4ee3\u7801\u96be\u4ee5\u7ef4\u62a4\u548c\u8c03\u8bd5\u3002\u56e0\u6b64\uff0c\u5728\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\u65f6\uff0c\u5e94\u8be5\u907f\u514d\u8fc7\u5ea6\u4f7f\u7528\u3001\u4f7f\u7528\u660e\u786e\u7684\u547d\u540d\uff0c\u5e76\u9650\u5236\u5168\u5c40\u53d8\u91cf\u7684\u4f7f\u7528\u8303\u56f4\u3002\u6b64\u5916\uff0c\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e2d\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\u65f6\uff0c\u9700\u8981\u7279\u522b\u6ce8\u610f\u7ebf\u7a0b\u5b89\u5168\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528\u7ebf\u7a0b\u9501\u548c\u7ebf\u7a0b\u5c40\u90e8\u5b58\u50a8\u6765\u786e\u4fdd\u7ebf\u7a0b\u5b89\u5168\u3002\u901a\u8fc7\u5408\u7406\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\uff0c\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u7ef4\u62a4\u6027\u548c\u6548\u7387\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u58f0\u660e\u4e00\u4e2a\u5168\u5c40\u53d8\u91cf\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u5728\u51fd\u6570\u5185\u90e8\u4f7f\u7528<code>global<\/code>\u5173\u952e\u5b57\u6765\u58f0\u660e\u5168\u5c40\u53d8\u91cf\u3002\u8fd9\u6837\uff0c\u60a8\u53ef\u4ee5\u5728\u51fd\u6570\u5185\u90e8\u4fee\u6539\u5168\u5c40\u4f5c\u7528\u57df\u4e2d\u7684\u53d8\u91cf\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a  <\/p>\n<pre><code class=\"language-python\">x = 10  # \u5168\u5c40\u53d8\u91cf\n\ndef modify_global():\n    global x  # \u58f0\u660ex\u4e3a\u5168\u5c40\u53d8\u91cf\n    x += 5  # \u4fee\u6539\u5168\u5c40\u53d8\u91cf\u7684\u503c\n\nmodify_global()\nprint(x)  # \u8f93\u51fa15\n<\/code><\/pre>\n<p><strong>\u5168\u5c40\u53d8\u91cf\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\u4f1a\u51fa\u73b0\u4ec0\u4e48\u95ee\u9898\uff1f<\/strong><br \/>\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e2d\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6570\u636e\u7ade\u4e89\u548c\u4e0d\u4e00\u81f4\u6027\u95ee\u9898\u3002\u5982\u679c\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u8bfb\u53d6\u548c\u5199\u5165\u5168\u5c40\u53d8\u91cf\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u610f\u5916\u7684\u7ed3\u679c\u3002\u4e3a\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\uff0c\u53ef\u4ee5\u4f7f\u7528\u7ebf\u7a0b\u9501\uff08\u5982<code>threading.Lock<\/code>\uff09\u6765\u786e\u4fdd\u5bf9\u5168\u5c40\u53d8\u91cf\u7684\u8bbf\u95ee\u662f\u5b89\u5168\u7684\u3002<\/p>\n<p><strong>\u4e3a\u4ec0\u4e48\u4e0d\u5efa\u8bae\u8fc7\u591a\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\uff1f<\/strong><br \/>\u8fc7\u591a\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\u4f1a\u4f7f\u4ee3\u7801\u96be\u4ee5\u7ef4\u62a4\u548c\u8c03\u8bd5\u3002\u5b83\u4eec\u589e\u52a0\u4e86\u4ee3\u7801\u7684\u590d\u6742\u6027\uff0c\u56e0\u4e3a\u5728\u4e0d\u540c\u7684\u5730\u65b9\u53ef\u80fd\u4f1a\u5bf9\u540c\u4e00\u4e2a\u53d8\u91cf\u8fdb\u884c\u4fee\u6539\uff0c\u8fd9\u6837\u4f1a\u5bfc\u81f4\u96be\u4ee5\u8ffd\u8e2a\u7684\u9519\u8bef\u3002\u4e3a\u4e86\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\uff0c\u5efa\u8bae\u5c3d\u91cf\u4f7f\u7528\u5c40\u90e8\u53d8\u91cf\uff0c\u5e76\u901a\u8fc7\u53c2\u6570\u4f20\u9012\u6216\u8fd4\u56de\u503c\u6765\u7ba1\u7406\u6570\u636e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u5c06\u53d8\u91cf\u8bbe\u7f6e\u4e3a\u5168\u5c40\u53d8\u91cf\u7684\u65b9\u6cd5\u4e3b\u8981\u6709\u4ee5\u4e0b\u51e0\u70b9\uff1a\u4f7f\u7528global\u5173\u952e\u5b57\u3001\u5c06\u53d8\u91cf\u5b9a\u4e49\u5728\u51fd\u6570\u5916\u90e8\u3001\u4f7f\u7528 [&hellip;]","protected":false},"author":3,"featured_media":1135288,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1135287"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1135287"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1135287\/revisions"}],"predecessor-version":[{"id":1135289,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1135287\/revisions\/1135289"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1135288"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1135287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1135287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1135287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}