This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients Santiago Blanco, docs@python, python-dev, remi.lapeyre, rhettinger
Date 2020-04-26.23:29:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <[email protected]>
In-reply-to
Content
I'm thinking of simplifying the example to focus on its core goal of demonstrating how to enqueue tasks and then wait for them to be finished:

    import threading, queue

    q = queue.Queue()

    def worker():
        while True:
            item = q.get()
            print(f'Working on {item}')
            print(f'Finished {item}')
            q.task_done()

    # turn-on the worker thread
    worker_thread = threading.Thread(target=worker)
    worker_thread.daemon = True
    worker_thread.start()

    # send thirty task requests to the worker
    for item in range(30):
        q.put(item)
    print('All task requests sent\n', end='')    

    # block until all tasks are done
    q.join()
    print('All work completed')
History
Date User Action Args
2020-04-26 23:29:34rhettingersetrecipients: + rhettinger, docs@python, python-dev, remi.lapeyre, Santiago Blanco
2020-04-26 23:29:34rhettingersetmessageid: <[email protected]>
2020-04-26 23:29:34rhettingerlinkissue40387 messages
2020-04-26 23:29:34rhettingercreate