Flask 開発サーバーが 2 回実行される: 理由を明らかにする
Flask 開発サーバーは、コードに変更が加えられるたびにアプリケーションの再起動を処理します。 。この機能は、Werkzeug ライブラリの restart_with_reloader() 関数によって提供されます。
この関数は子プロセスを生成し、subprocess.call() を使用してスクリプトを再度実行します。その結果、元のスクリプトと子プロセスの両方が再起動メッセージを 1 回ずつ出力し、二重出力動作が観察されます。
リローダーを無効にします
この動作を排除するには、 use_reloader を False に設定してリローダーを無効にします:
app.run(port=4004, debug=config.DEBUG, host='0.0.0.0', use_reloader=False)
または、 --no-reload フラグを指定した flask run コマンド:
FLASK_DEBUG=1 flask run --no-reload
リローダー プロセスを検出する
werkzeug.serving.is_running_from_reloader() 関数を使用して、子プロセス:
from werkzeug.serving import is_running_from_reloader if is_running_from_reloader(): print(f"################### Restarting @ {datetime.utcnow()} ###################")
を使用します@app.before_first_request デコレータ
モジュール グローバルを設定する必要がある場合は、@app.before_first_request デコレータの使用を検討してください。
@app.before_first_request def before_first_request(): print(f"########### Restarted, first request @ {datetime.utcnow()} ############")
このデコレータは、リロードのたびに関数を 1 回実行します。最初のリクエストのとき
注:
フォークまたはサブプロセスを使用してリクエストを処理する本格的な WSGI サーバーでは、サブプロセスごとに before_first_request ハンドラーが呼び出される場合があります。
以上がFlask 開発サーバーが 2 回実行されているように見えるのはなぜですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

pythonusesahybridmodelofcompilation andtertation:1)thepythoninterpretercompilessourcodeodeplatform-indopent bytecode.2)thepythonvirtualmachine(pvm)thenexecuteTesthisbytecode、balancingeaseoputhswithporformance。

pythonisbothintersedand compiled.1)it'scompiledtobytecode forportabalityacrossplatforms.2)bytecodeisthenは解釈され、開発を許可します。

loopsareideal whenyouwhenyouknumberofiterationsinadvance、foreleloopsarebetterforsituationsは、loopsaremoreedilaConditionismetを使用します

henthenumber ofiterationsisknown advanceの場合、dopendonacondition.1)forloopsareideal foriterating over for -for -for -saredaverseversives likelistorarrays.2)whileopsaresupasiable forsaresutable forscenarioswheretheloopcontinupcontinuspificcond

pythonisnotpurelyLepted; itusesahybridapproachofbytecodecodecodecodecodecodedruntimerttation.1)pythoncompilessourcodeintobytecode、whodythepythonvirtualmachine(pvm).2)

ToconcatenateListsinpythothesheElements、使用:1)Operatortokeepduplicates、2)asettoremoveduplicates、or3)listcomplunting for controloverduplicates、各メトドハスディフェルフェルフェントパフォーマンスアンドソーダーインプリテーション。

pythonisantertedlanguage、useaseofuseandflexibility-butfactingporformantationationsincriticalapplications.1)解釈されたlikepythonexecuteline-by-lineを解釈します

Useforloopswhenthenumberofiterationsisknowninadvance、andwhiloopswheniterationsdependonacondition.1)forloopsareidealforsecenceslikelistoranges.2)


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

VSCode Windows 64 ビットのダウンロード
Microsoft によって発売された無料で強力な IDE エディター

mPDF
mPDF は、UTF-8 でエンコードされた HTML から PDF ファイルを生成できる PHP ライブラリです。オリジナルの作者である Ian Back は、Web サイトから「オンザフライ」で PDF ファイルを出力し、さまざまな言語を処理するために mPDF を作成しました。 HTML2FPDF などのオリジナルのスクリプトよりも遅く、Unicode フォントを使用すると生成されるファイルが大きくなりますが、CSS スタイルなどをサポートし、多くの機能強化が施されています。 RTL (アラビア語とヘブライ語) や CJK (中国語、日本語、韓国語) を含むほぼすべての言語をサポートします。ネストされたブロックレベル要素 (P、DIV など) をサポートします。

MantisBT
Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

メモ帳++7.3.1
使いやすく無料のコードエディター

SAP NetWeaver Server Adapter for Eclipse
Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。
