1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Flaskの二重ロードでハマったのでメモを残す

Posted at

問題

Flaskを動作させているWebサーバー側でSeleniumを利用して下記のようにブラウザを起動したい。
この処理が二重に呼び出される不具合が発生した。

self.driver = webdriver.Chrome()

問題発生の原因

Flask を debug=True で実行した場合、リローダを使って変更を開始してファイルに変更が検出されるとアプリケーションを」自動的に再起動している。この動作のためFlaskは2つのプロセスを起動している。このため其々のプロセスで同じコードが呼び出されるため二重起動していた。

問題解決方法

use_reloaderオプションをFalseに設定することでリローダを無効にする。ただし。リローダを無効にすると、変更を監視して自動的にアプリケーションを再起動する機能は利用できなくなる

app.run(host="0.0.0.0", port=8080, debug=True, use_reloader=False)
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?