user2171584
user2171584

Reputation: 1633

python losing global list contents from child process

I have a global list that I append to in a child process. Meanwhile the function that called the child process is iterating through the list. When the child process is exited, the global list is empty, even though I appended to it

urlsToCheck = list()

def crawler():
    while limit != 0 and urlsToCheck.__len__() > 0:
        curUrl = urlsToCheck.pop(0)
        processLink(curUrl)
        limit -= 1

def processLink(url):
    ...
    for i in validLinks:
        urlsToCheck.append(i)
    ...

Upvotes: 0

Views: 71

Answers (1)

falsetru
falsetru

Reputation: 369344

Variables are not shared between processes unless if you use shared data structure explicitly.

See multiprocessing documentation - Sharing state between processes.

Upvotes: 1

Related Questions