Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python线程错误与WindowsError 2相结合_Python - Fatal编程技术网

Python线程错误与WindowsError 2相结合

Python线程错误与WindowsError 2相结合,python,Python,以下是我目前正在编写的代码: import requests import subprocess import json import sys import threading import time from Queue import Queue numberOfViewers = int(sys.argv[1]) builderThreads = int(sys.argv[2]) startTime = time.time() numberOfSockets = 0 concurrent

以下是我目前正在编写的代码:

import requests
import subprocess
import json
import sys
import threading
import time
from Queue import Queue

numberOfViewers = int(sys.argv[1])
builderThreads = int(sys.argv[2])
startTime = time.time()
numberOfSockets = 0
concurrent = 5
urls = []
urlsUsed = []

def getURL(): # Get tokens
      output = subprocess.Popen(["livestreamer", "twitch.tv/testchannel", "-j"], stdout=subprocess.PIPE).communicate()[0]
      return json.loads(output)['streams']['worst']['url'] # Parse json and return the URL parameter

def build(): # Builds a set of tokens, aka viewers
    global numberOfSockets
    global numberOfViewers
    while True:
        if numberOfSockets < numberOfViewers:
            numberOfSockets += 1
            print "Building viewers " + str(numberOfSockets) + "/" + str(numberOfViewers)
            urls.append(getURL())

def view(): # Opens connections to send views
    global numberOfSockets
    while True:
        url=q.get()
        requests.head(url)
        if (url in urlsUsed):
            urls.remove(url)
            urlsUsed.remove(url)
            numberOfSockets -= 1
        else:
            urlsUsed.append(url)
        q.task_done()

if __name__ == '__main__':
    for i in range(0, builderThreads):
        threading.Thread(target = build).start()

    while True:
        while (numberOfViewers != numberOfSockets): # Wait until sockets are built
            time.sleep(1)

        q=Queue(concurrent*2)
        for i in range(concurrent):
            try:
                t=threading.Thread(target=view)
                t.daemon=True
                t.start()
            except:
                print 'thread error' + 'jk'
        try:
            for url in urls:
                print url
                q.put(url.strip())
                q.join()
        except KeyboardInterrupt:
            sys.exit(1)
我只到了cmd输出这个错误的地方,我的代码开始输出“threaderror”。


我试着研究这个问题,我也试着搞乱t.Daemon的值,但是运气不好。

看起来它找不到
“livestreamer”
是什么。这是你人生道路上应该存在的东西吗?它在你启动python的目录中吗?当然,我很笨。当我转到新安装时,我忘记使用“pip安装livestreamer”。谢谢你的帮助!
C:\Python27\python.exe C:\Python27\twh.py 5 4