python3(iperf3)で使用する必要があるライブラリの1つは、ライブラリ 'run'の機能がメインスレッドで実行されるである必要があります。マルチプロセスでの新しいプロセスはメインスレッドで実行できますか?
マルチプロセスの新しいプロセスであるライブラリがプロセスのメインスレッドを使用できるようにするためにいくつかのテストを行っていますが、上記のスニペットでは新しい 'メインスレッド'プロセス。
フォークされたプロセスを新しいプロセスのメインスレッドとして実行するには、どのような方法が推奨されますか?それは可能ですか? Celeryのようなシステムはこれを手助けしますか?私はFlaskアプリからこれを実行する予定です。
ありがとうございます!
#! /usr/bin/python3
import threading
import multiprocessing as mp
def mp_call():
try:
print("mp_call is mainthread? {}".format(isinstance(threading.current_thread(), threading._MainThread)))
except Exception as e:
print('create iperf e:{}'.format(e))
def thread_call():
try:
print("thread_call is mainthread? {}".format(isinstance(threading.current_thread(), threading._MainThread)))
p = mp.Process(target=mp_call, args=[])
p.daemon = False
p.start()
p.join()
print('Process ended')
except Exception as e:
print('thread e:{}'.format(e))
t = threading.Thread(target=thread_call)
t.daemon = False
t.start()
t.join()
print('Thread ended')
フラスコアプリではマルチプロセッシングを使用しないでください。それはWSGIサーバーであらゆる種類の問題につながります。サーバーには独自のプロセスとスレッドシステムがあります。 @KlausD。 –
あなたは何を使用することをお勧めしますか?セロリ? – h3ct0r
@georgexsh今のところ、iperf3モジュールにいくつかの変更を加えました。これらのジョブを実行するためにセロリを自分のプロジェクトに統合して、すべてが動作していることを報告します。 – h3ct0r