Skip to content

WaitGroup.add(count) inconsistency #1

@griffrawk

Description

@griffrawk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions