Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WaitGroup.add(count) inconsistency #1

Open
griffrawk opened this issue Dec 3, 2022 · 0 comments
Open

WaitGroup.add(count) inconsistency #1

griffrawk opened this issue Dec 3, 2022 · 0 comments

Comments

@griffrawk
Copy link

griffrawk commented Dec 3, 2022

Allowing WaitGroup.add(count) to accept a value to be added to WaitGroup.wait_count seems to be inconsistent with WaitGroup.done() which only ever decrements the count by 1.

A thread could be started and the code erroneously adds a count > 1 to the WaitGroup by misusing the parameters. The main thread will never end (the WaitGroup.wait() continues to loop) because the child threads never reduce the count to zero. I've tried this in the concurrent file search example.

def file_search(root, filename, wait_group):
    print("Searching in:", root)
    for file in os.listdir(root):
        full_path = join(root, file)
        if filename in file:
            mutex.acquire()
            matches.append(full_path)
            mutex.release()
        if isdir(full_path):
            wait_group.add(2)
            t = Thread(target=file_search, args=([full_path, filename, wait_group]))
            t.start()
    wait_group.done()

Of course this is simply a programmer problem, unlikely to happen, but looks inconsistent for the example. Unfortunately this is baked into your video.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant