Skip to content

queue example is a sketch #84567

Closed
Closed

Description

@sblancov
mannequin
BPO 40387
Nosy @rhettinger, @miss-islington, @remilapeyre, @sblancov
PRs
  • bpo-40387: Fix example code for Queue.join #19713
  • bpo-40387 Improve queue join() example. #19724
  • [3.8] bpo-40387: Improve queue join() example. (GH-19724) #19726
  • Files
  • example.py: A working example
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/rhettinger'
    closed_at = <Date 2020-04-27.01:24:14.447>
    created_at = <Date 2020-04-25.07:58:55.598>
    labels = ['type-feature', '3.8', '3.9', 'docs']
    title = 'queue example is a sketch'
    updated_at = <Date 2020-04-27.01:24:14.446>
    user = 'https://github.com/sblancov'

    bugs.python.org fields:

    activity = <Date 2020-04-27.01:24:14.446>
    actor = 'rhettinger'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2020-04-27.01:24:14.447>
    closer = 'rhettinger'
    components = ['Documentation']
    creation = <Date 2020-04-25.07:58:55.598>
    creator = 'Santiago Blanco'
    dependencies = []
    files = ['49092']
    hgrepos = []
    issue_num = 40387
    keywords = ['patch']
    message_count = 8.0
    messages = ['367263', '367274', '367279', '367323', '367333', '367336', '367338', '367339']
    nosy_count = 6.0
    nosy_names = ['rhettinger', 'docs@python', 'python-dev', 'miss-islington', 'remi.lapeyre', 'Santiago Blanco']
    pr_nums = ['19713', '19724', '19726']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue40387'
    versions = ['Python 3.8', 'Python 3.9']

    Activity

    1. sblancov commented on Apr 25, 2020

      sblancovmannequin
      MannequinAuthor

      Copy the example of the next URL:

      https://docs.python.org/3/library/queue.html#queue.Queue.join

      and paste into a file, then try to run it. It does not work.

      I have tried a new one (attachment) that works.

    2. added
      3.7 (EOL)
      3.8 (EOL)
      3.9 (EOL)
      docs
      type-feature
      on Apr 25, 2020
    3. added
      3.7 (EOL)
      3.8 (EOL)
      3.9 (EOL)
      docs
      type-feature
      on Apr 25, 2020
    4. remilapeyre commented on Apr 25, 2020

      remilapeyremannequin
      Mannequin

      In general examples in the documentation may lack some things like imports as they are implicit but in this case it also lack do_work(), source() and num_worker_threads.

      You could use os.cpu_count() instead of your hard-coded value and the comment.

      Can you open a pull request with your change?

    5. rhettinger commented on Apr 25, 2020

      @rhettinger
      Contributor

      The example is supposed to be a sketch of the overall pattern. IMO, putting concrete and useless implementations of do_work() and source() make the example less intelligible.

      Instead, we can add a note that the user needs to supply their own do_work() and source().

    6. 1 remaining item

    7. rhettinger commented on Apr 26, 2020

      @rhettinger
      Contributor

      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')
    8. changed the title [-]queue example it does not work[/-] [+]queue example is a sketch[/+] on Apr 26, 2020
    9. changed the title [-]queue example it does not work[/-] [+]queue example is a sketch[/+] on Apr 26, 2020
    10. sblancov commented on Apr 27, 2020

      sblancovmannequin
      MannequinAuthor

      That is pretty clear! Thank you Raymond.

    11. rhettinger commented on Apr 27, 2020

      @rhettinger
      Contributor

      New changeset 88499f1 by Raymond Hettinger in branch 'master':
      bpo-40387: Improve queue join() example. (GH-19724)
      88499f1

    12. rhettinger commented on Apr 27, 2020

      @rhettinger
      Contributor

      New changeset 179f22c by Miss Islington (bot) in branch '3.8':
      bpo-40387: Improve queue join() example. (GH-19724) (GH-19726)
      179f22c

    13. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    3.8 (EOL)3.9 (EOL)docstype-feature

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions