Coryza
Coryza

Reputation: 251

Memory keeps getting up during Threading with Python

I have a problem with Threading in Python. The Memory keeps getting up (pythonw.exe).. it starts with +- 20.000 kB, but keeps rising untill the programm is finished. Anyone knows how to fix this?

class Threads(threading.Thread):
    def run(self):
        try:
            HTML = urllib2.urlopen(//URL//).read()
        except urllib2.HTTPError: pass
        except: pass

def __Scan__():
    Count = 0
    while Count <10000:
        Count = Count + 1
        try:
            Thread = Threads()
            Thread.name = Count
            Thread.start()
        except:
            Count = Count - 1

Each Thread will open an URL, and then I store the number of the Thread in a list. But I don't think thats the cause of the rising memory? Anyone can help?

Thx

Upvotes: 0

Views: 1222

Answers (1)

jeffknupp
jeffknupp

Reputation: 6314

The increase in memory is likely from the stack space created for each new thread. Threads in Python (and most other languages) have a certain amount of resource overhead. Each time you create one, a little bit of memory is allocated for it.

Upvotes: 1

Related Questions