Skip to content

queue.Queue repeats items sometimes #3153

Closed

Description

@clayote

On desktop, this script runs fine, but on Android, items late in the output queue repeat.

It seems to have something to do with the queue getting big. Not anywhere near its maximum size, just big.

Activity

  1. clayote commented on May 13, 2025

    @clayote
    ContributorAuthor

    It seems to relate to the particulars of the items put into the queue. I tried replacing most of the data with empty lists and the issue went away.

  2. clayote commented on May 13, 2025

    @clayote
    ContributorAuthor

    I cut down the script to 55 lines.

  3. clayote commented on May 13, 2025

    @clayote
    ContributorAuthor

    53 now. I'll stop here.

    I thought that big or numerous enqueued items made a difference, but it turns out that six empty lists and some tuples are enough.

  4. clayote commented on May 13, 2025

    @clayote
    ContributorAuthor

    When I simplify the final loop like this

    for i in range(6):
    	inq.put(("echo", ("begin", i)))
    	inq.put((None,))
    	inq.put(("echo", ("end", i)))
    for i in range(6):
    	assert outq.get() == ("begin", i)
    	got = outq.get()
    	assert isinstance(got, list)
    	got = outq.get()
    	assert got == ("end", i)

    the bug appears.

    But when I do it like this

    for i in range(6):
    	assert outq.get() == ("begin", i)
    	assert isinstance(outq.get(), list)
    	assert outq.get() == ("end", i)

    it doesn't, and things are fine.

    So it's got a bit to do with the intermediate variable got.

  5. clayote commented on May 13, 2025

    @clayote
    ContributorAuthor

    This is the output on Android:

    outq should be empty, but isn't. Here's what's in it:
    ('begin', 4)
    []
    ('end', 4)
    ('begin', 5)
    []
    ('end', 5)
    
  6. clayote commented on May 13, 2025

    @clayote
    ContributorAuthor
  7. clayote commented on May 13, 2025

    @clayote
    ContributorAuthor

    This wasn't really a bug -- you're not supposed to use asserts like that. Thanks to @Cheaterman for figuring this out.

  8. clayote commented on May 13, 2025

    @clayote
    ContributorAuthor

    python-for-android always compiles installed libraries into bytecode, even if you're doing a "debug" build; so the asserts in the linked scripts were being removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions