{"id":46634,"date":"2020-03-01T01:24:00","date_gmt":"2020-02-29T17:24:00","guid":{"rendered":"http:\/\/www.xyryd.com\/?p=46634"},"modified":"2020-03-01T01:24:01","modified_gmt":"2020-02-29T17:24:01","slug":"python-%e8%b7%a8%e6%96%87%e4%bb%b6-function%e5%87%bd%e6%95%b0-%e5%ae%9a%e4%b9%89%e5%85%a8%e5%b1%80%e5%8f%98%e9%87%8f-%e4%bb%a3%e7%a0%81%e5%ae%9e%e4%be%8b","status":"publish","type":"post","link":"http:\/\/www.xyryd.com\/46634.html","title":{"rendered":"Python \u8de8\u6587\u4ef6 function\u51fd\u6570 \u5b9a\u4e49\u5168\u5c40\u53d8\u91cf \u4ee3\u7801\u5b9e\u4f8b"},"content":{"rendered":"\n
\u8001\u5b63\u662fPython\u65b0\u624b\uff0c\u4e0b\u9762\u6211\u4eec\u8bb0\u5f55\u4e00\u4e0b\u5982\u4f55\u8de8\u6587\u4ef6\u5b9a\u4e49\u4e00\u4e2a\u5168\u5c40\u53d8\u91cf\u3002<\/p>\n\n\n\n
\u6211\u4eec\u9700\u8981\u5728main.py\u3001cmss.py\u91cc\u5b9a\u4e49\u4e86\u4e00\u4e2a\u53d8\u91cf\uff0clockfile \u5f53\u7136\u8fd9\u91cc\u6587\u4ef6\u91cc\u7684\u5404\u4e2a\u503c\u662f\u4e0d\u540c\u7684\u3002\u6211\u4eec\u5982\u4f55\u5728func.py\u7684\u51fd\u6570\u91cc\u4f7f\u7528\u8fd9\u4e2alockfile\u7684\u503c\u5462\uff1f<\/p>\n\n\n\n
\u5f00\u59cb\u6211\u4eec\u4f7f\u7528\u7684\u662f global lockfile \u65b9\u6cd5\uff0c\u8fd9\u79cd\u53ea\u80fd\u5728\u5355\u6587\u4ef6\u91cc\u8d4b\u503c\uff0c\u6bd4\u5982\uff1a<\/p>\n\n\n\n
lockfile = 1\ndef jrun():\n global lockfile \n return lockfile+2<\/code><\/pre>\n\n\n\n\u8fd9\u6837\u7684\u8bdd\u53ef\u4ee5\u6b63\u5e38\u8fd0\u884c\uff0c\u8fd4\u56de3 \u3002\u4f46\u662f\u5982\u679c\u6211\u4eec\u628ajrun()\u653e\u5165\u5230\u53e6\u5916\u4e00\u4e2a\u6587\u4ef6\u91cc\uff0c\u5c31\u65e0\u6cd5\u8fd0\u884c\u4e86\u3002\u56e0\u4e3a\u5728\u8fd9\u4e2apy\u6a21\u5757\u4e2d\u5e76\u6ca1\u6709\u4e00\u4e2a\u53eb\u505alockfile\u7684\u53d8\u91cf\uff0c\u4e8e\u662f\u5c31\u4f1a\u62a5\u9519\u672a\u5b9a\u4e49\u3002 \u4e0b\u9762\u6211\u4eec\u7ed9\u51fa\u6b63\u786e\u7684\u65b9\u6cd5\u3002<\/p>\n\n\n\n