curl
n 個のスレッドを作成し、各スレッドが Web アプリで m 回呼び出す小さな python スクリプトを作成しています。
スクリプトが呼び出されます ./multithreadedCurl.py 10 100
curl が 10*100 = 1000 回実行されることを期待しています。ただし、n個のスレッドを作成していることがわかりますが、各スレッドはcurlを1回しか呼び出していません。
これは、サブプロセスを使用しているという事実によるものですか?
Python バージョン Python 2.7.2 OS: Mac OSX 10.8.2 (Mountain Lion)
どんな助けでも大歓迎です。私はPythonに非常に慣れていません。これは、Python開発の2日目です。
#!/usr/bin/python
import threading
import time
import subprocess
import sys
import math
# Define a function for the thread
def run_command():
count = 0
while (count < int(sys.argv[2])):
subprocess.call(["curl", "http://127.0.0.1:8080"])
count += 1
threadCount = 0
print sys.argv[0]
threadLimit = int(sys.argv[1])
while threadCount < threadLimit:
t=threading.Thread(target=run_command)
t.daemon = True # set thread to daemon ('ok' won't be printed in this case)
t.start()
threadCount += 1`