Skip to content

Instantly share code, notes, and snippets.

@clayote
Last active May 13, 2025 17:09
Show Gist options
  • Save clayote/84e42ada03bd68319e45d9d4eae2e02e to your computer and use it in GitHub Desktop.
Save clayote/84e42ada03bd68319e45d9d4eae2e02e to your computer and use it in GitHub Desktop.
This program runs OK on desktop, but on Android, data reappears in the queue after it's been removed and processed.
import sys
from queue import SimpleQueue
from threading import Thread
from kivy.app import App
from kivy.clock import Clock
from kivy.logger import Logger
from kivy.uix.label import Label
DATA = [[], [], [], [], [], []]
def subthread(inq, outq):
it = iter(DATA)
while True:
inst = inq.get()
if inst[0] == "echo":
outq.put(inst[1])
else:
outq.put(next(it))
class TinyApp(App):
def on_start(self):
self.inq = inq = SimpleQueue()
self.outq = outq = SimpleQueue()
thread = Thread(target=subthread, args=[inq, outq], daemon=True)
thread.start()
for i in range(6):
inq.put(("echo", ("begin", i)))
inq.put((None,))
inq.put(("echo", ("end", i)))
Clock.schedule_once(self.read, 0)
def read(self, *_):
outq = self.outq
for i in range(6):
assert outq.get() == ("begin", i)
got = outq.get()
assert isinstance(got, list)
got = outq.get()
assert got == ("end", i)
if outq.qsize() != 0:
msg = "outq should be empty, but isn't. Here's what's in it:"
Logger.error("outq should be empty, but isn't. Here's what's in it:")
while outq.qsize() != 0:
got = outq.get()
msg += "\n" + repr(got)
Logger.error(msg)
self.label.text = msg
return
Logger.info("Everything worked")
self.label.text = "OK"
def build(self):
self.label = Label(text="Working...")
return self.label
if __name__ == "__main__":
Logger.setLevel(10)
app = TinyApp()
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment