問題タブ [flask-script]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票する
1 に答える
1795 参照

python - 各 uwsgi ワーカーで初期化コードを実行する方法はありますか (フォーク後)

スポーン後にできるだけ早く各ワーカーで実行する関数を登録する方法はありますか (uWSGI または Flask で) 。

たくさんのものをプリロードすることで恩恵を受けるフラスコアプリがあります。preload以下は、8 つのワーカー プロセスに対して 1 回だけ呼び出します。最初のリクエストは高速ですが、プリロードされたオブジェクトは何らかの方法で共有され、エラーが発生します。

before_first_requestを使用すると、オブジェクトは各ワーカー プロセスに読み込まれ、エラーは発生しませんが、最初のリクエストは非常に遅くなります。

フラスコスクリプトも設定してみました。コマンドの実行は機能しますが、明らかに、オブジェクトは uwsgi ワーカーではなくコマンドのプロセスで読み込まれます。

を使用するbefore_first_requestと、uwsgi の再起動後に手動でリクエストをトリガーできると思います。それがここでの唯一の解決策ですか?

編集: uswgi hook-post-forkオプション (およびその他のフック オプション) が見つかりました。明日それを試してみます。多分それらの1つは私が必要とするものです。

0 投票する
1 に答える
52 参照

flask-sqlalchemy - Flask-migrate change db before upgrade

I have a multi-tenancy structure set up where each client has a schema set up for them. The structure mirrors the "parent" schema, so any migration that happens needs to happen for each schema identically.

I am using Flask-Script with Flask-Migrate to handle migrations.

What I tried so far is iterating over my schema names, building a URI for them, scoping a new db.session with the engine generated from the URI, and finally running the upgrade function from flask_migrate.

I am not entirely sure why this doesn't work, but the result is that it only runs the migration for the db that was set up when the application starts.

My theory is that I am not changing the session that was originally set up when the manager script runs.

Is there a better way to migrate each of these schemas without setting multiple binds and using the --multidb parameter? I don't think I can use SQLALCHEMY_BINDS in the config since these schemas need to be able to be dynamically created/destroyed.