タグ

ブックマーク / qiita.com/castaneai (1)

  • Pythonの並列・並行処理サンプルコードまとめ - Qiita

    Pythonで同時に2つ以上の処理をする方法を紹介します スレッド スレッドプール プロセスプール イベントループ(コルーチン) スレッド (threading) スレッドを使えば、複数の関数を同時に動かすことができます。 threading.Thread クラスに target として関数を渡し、start() で開始すると動きます。 import time import threading def func1(): while True: print("func1") time.sleep(1) def func2(): while True: print("func2") time.sleep(1) if __name__ == "__main__": thread_1 = threading.Thread(target=func1) thread_2 = threading.Thr

    Pythonの並列・並行処理サンプルコードまとめ - Qiita
  • 1