LoginSignup
0
0

More than 1 year has passed since last update.

React+Socket.ioの画面からCelery経由でPythonプログラムを呼び出すやつ

Posted at

探しても見つからなかったので自分で書いた。

起動方法

Reactクライアント

cd client
npm install
npm start

Socket.ioサーバー

cd server
npm install
node index.js

Pythonプログラム

Windows環境だと -P solo を付けないと動かないので注意。あと、CeleryはWindowsを正式にはサポートしていないので、あくまでもテスト用とすること。

cd worker
pip install -r requirements.txt
celery -A tasks worker -P solo

どこが素晴らしいのか

Node.jsのサーバーからPythonプログラムを非同期で呼ぶようにすることで、Flask-SocketIOでゴリゴリ書くよりもシンプルかつコンパクトになる。たとえば、Pythonで書かれた機械学習のプログラムを呼び出したりなんかしても面白い。というか、まさにそれ用に作った。

その他

テスト用にRedisを無料で使いたい場合

RedisLabsで無料版あり。クレジットカードの登録等も不要。

0
0
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
0
0