Python multithreading freeze(?) randomly
<p>I'm writing a script that's supposed to get some pictures from a very large amount or websites. First time using multithreading, think it is required here so get an okay runtime. So the Problem: The script runs, but after a seemingly random amount of passed websites it just doesn't continue any more. It doesn't totally freeze tho, the time just goes up from what feels like 1/100 of a sec. to several minutes or so, sometimes so long id just close it instead. Also it doesn't seem like some of the websites are responsible in particular, sometimes it get 970, the only 200 entries. Here the relevant parts of the code:</p>

<pre><code>concurrent = 200
q = Queue(concurrent * 2)

def main(listPath, usagePath, idListPath):
    [...]
    for i in range(concurrent):
        t = Thread(target=work)
        t.daemon = True
        t.start()
    try: 
        for code in usedIDs:
            q.put(code)
        q.join()

    except KeyboardInterrupt:
        sys.exit(1)


def work():
    while True:
        code = q.get()
        picture = getPicture(code)
        if picture is None:
            pass  # todo: find other source or default
        if not code in usage.keys():
            usage[code] = list()
        usage[code].append(picture)
        q.task_done()
</code></pre>

<p>Hope i got all the important code there. Thanks in advance! </p>

<p>My bad guys, the problem was actually in the getPicture function. Thanks for the answers anyways!</p>

python multithreading freeze