{"id":5947,"date":"2025-07-20T17:06:10","date_gmt":"2025-07-20T09:06:10","guid":{"rendered":"http:\/\/192.168.1.29\/?p=5947"},"modified":"2025-07-20T17:06:10","modified_gmt":"2025-07-20T09:06:10","slug":"python-waitress%e6%a8%a1%e5%9d%97-%e5%8f%af%e6%9b%bf%e4%bb%a3flask-%e7%9a%84%e5%bc%80%e5%8f%91%e7%8e%af%e5%a2%83%e5%90%97","status":"publish","type":"post","link":"http:\/\/xc.ipyingshe.net:5347\/?p=5947","title":{"rendered":"python waitress\u6a21\u5757 \u53ef\u66ff\u4ee3flask \u7684\u5f00\u53d1\u73af\u5883\u5417"},"content":{"rendered":"\n<p>\u662f\u7684\uff0cPython\u7684<code>waitress<\/code>\u6a21\u5757\u53ef\u4ee5\u66ff\u4ee3Flask\u81ea\u5e26\u7684\u5f00\u53d1\u670d\u52a1\u5668\uff0c\u800c\u4e14\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u66f4\u63a8\u8350\u4f7f\u7528<code>waitress<\/code>\u8fd9\u6837\u7684WSGI\u670d\u52a1\u5668\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u8bf4\u660e\uff1a<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Flask\u81ea\u5e26\u670d\u52a1\u5668\u7684\u5c40\u9650\u6027<\/strong><\/h3>\n\n\n\n<p>Flask\u5185\u7f6e\u7684\u670d\u52a1\u5668\uff08\u901a\u8fc7<code>app.run()<\/code>\u542f\u52a8\uff09\u662f\u4e3a\u5f00\u53d1\u73af\u5883\u8bbe\u8ba1\u7684\uff0c\u5b83\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5355\u7ebf\u7a0b\u8fd0\u884c<\/strong>\uff1a\u65e0\u6cd5\u5904\u7406\u5e76\u53d1\u8bf7\u6c42\uff0c\u6027\u80fd\u5dee\u3002<\/li>\n\n\n\n<li><strong>\u5b89\u5168\u6027\u4f4e<\/strong>\uff1a\u7f3a\u4e4f\u751f\u4ea7\u7ea7\u7684\u5b89\u5168\u52a0\u56fa\u3002<\/li>\n\n\n\n<li><strong>\u7a33\u5b9a\u6027\u4e0d\u8db3<\/strong>\uff1a\u957f\u65f6\u95f4\u8fd0\u884c\u53ef\u80fd\u5d29\u6e83\uff0c\u4e0d\u9002\u5408\u9ad8\u8d1f\u8f7d\u573a\u666f\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Waitress\u7684\u4f18\u52bf<\/strong><\/h3>\n\n\n\n<p><code>waitress<\/code>\u662f\u4e00\u4e2a\u7eafPython\u5b9e\u73b0\u7684WSGI\u670d\u52a1\u5668\uff0c\u4e13\u4e3a\u751f\u4ea7\u73af\u5883\u8bbe\u8ba1\uff0c\u5177\u6709\u4ee5\u4e0b\u7279\u70b9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u591a\u7ebf\u7a0b\u652f\u6301<\/strong>\uff1a\u9ed8\u8ba4\u542f\u7528\u591a\u7ebf\u7a0b\u5904\u7406\u8bf7\u6c42\uff0c\u5927\u5e45\u63d0\u5347\u5e76\u53d1\u80fd\u529b\u3002<\/li>\n\n\n\n<li><strong>\u8de8\u5e73\u53f0\u517c\u5bb9<\/strong>\uff1a\u652f\u6301Linux\u3001Windows\u3001macOS\u7b49\u3002<\/li>\n\n\n\n<li><strong>\u7a33\u5b9a\u6027\u9ad8<\/strong>\uff1a\u9002\u5408\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u5e94\u7528\u3002<\/li>\n\n\n\n<li><strong>\u5b89\u88c5\u7b80\u5355<\/strong>\uff1a\u901a\u8fc7<code>pip install waitress<\/code>\u5373\u53ef\u5b89\u88c5\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. \u5982\u4f55\u7528Waitress\u8fd0\u884cFlask\u5e94\u7528<\/strong><\/h3>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u5c06Flask\u5e94\u7528\u4ece\u5f00\u53d1\u670d\u52a1\u5668\u5207\u6362\u5230<code>waitress<\/code>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from flask import Flask\n\napp = Flask(__name__)\n\n@app.route('\/')\ndef hello():\n    return \"Hello, World!\"\n\nif __name__ == '__main__':\n    # \u5f00\u53d1\u73af\u5883\uff1a\u4f7f\u7528Flask\u5185\u7f6e\u670d\u52a1\u5668\n    # app.run(debug=True)\n\n    # \u751f\u4ea7\u73af\u5883\uff1a\u4f7f\u7528waitress\u670d\u52a1\u5668\n    from waitress import serve\n    serve(app, host='0.0.0.0', port=8080)<\/code><\/pre>\n\n\n\n<p><strong>\u5173\u952e\u533a\u522b<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5f00\u53d1\u65f6<\/strong>\uff1a\u4f7f\u7528<code>app.run()<\/code>\uff0c\u53ef\u5f00\u542f\u8c03\u8bd5\u6a21\u5f0f\uff08<code>debug=True<\/code>\uff09\u3002<\/li>\n\n\n\n<li><strong>\u90e8\u7f72\u65f6<\/strong>\uff1a\u4f7f\u7528<code>serve(app, host='0.0.0.0', port=8080)<\/code>\uff0c\u5173\u95ed\u8c03\u8bd5\u6a21\u5f0f\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. \u751f\u4ea7\u73af\u5883\u7684\u5176\u4ed6\u5efa\u8bae<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u53cd\u5411\u4ee3\u7406<\/strong>\uff1a\u5728<code>waitress<\/code>\u524d\u4f7f\u7528Nginx\u6216Apache\u4f5c\u4e3a\u53cd\u5411\u4ee3\u7406\uff0c\u5904\u7406\u9759\u6001\u6587\u4ef6\u548c\u8d1f\u8f7d\u5747\u8861\u3002<\/li>\n\n\n\n<li><strong>\u8fdb\u7a0b\u7ba1\u7406\u5668<\/strong>\uff1a\u7ed3\u5408<code>systemd<\/code>\u6216<code>supervisor<\/code>\u7ba1\u7406\u5e94\u7528\u8fdb\u7a0b\uff0c\u786e\u4fdd\u81ea\u52a8\u91cd\u542f\u3002<\/li>\n\n\n\n<li><strong>\u73af\u5883\u5206\u79bb<\/strong>\uff1a\u4f7f\u7528<code>.env<\/code>\u6587\u4ef6\u6216\u73af\u5883\u53d8\u91cf\u533a\u5206\u5f00\u53d1\u548c\u751f\u4ea7\u914d\u7f6e\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u603b\u7ed3<\/strong><\/h3>\n\n\n\n<p><code>waitress<\/code>\u5b8c\u5168\u53ef\u4ee5\u66ff\u4ee3Flask\u7684\u5f00\u53d1\u670d\u52a1\u5668\uff0c\u5e76\u4e14\u66f4\u9002\u5408\u751f\u4ea7\u73af\u5883\u3002\u5b83\u63d0\u4f9b\u4e86\u66f4\u597d\u7684\u6027\u80fd\u548c\u7a33\u5b9a\u6027\uff0c\u540c\u65f6\u4fdd\u6301\u4e86Python\u7684\u7b80\u6d01\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u662f\u7684\uff0cPython\u7684waitress\u6a21\u5757\u53ef\u4ee5\u66ff\u4ee3Flask\u81ea\u5e26\u7684\u5f00\u53d1\u670d\u52a1\u5668\uff0c\u800c\u4e14 <span class=\"readmore\"><a href=\"http:\/\/xc.ipyingshe.net:5347\/?p=5947\">Continue Reading<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-5947","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/5947","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5947"}],"version-history":[{"count":1,"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/5947\/revisions"}],"predecessor-version":[{"id":5948,"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/5947\/revisions\/5948"}],"wp:attachment":[{"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5947"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}