Skip to content

Instantly share code, notes, and snippets.

@clayote
Created May 13, 2025 17:05
Show Gist options
  • Select an option

  • Save clayote/d2489a7052a76fcc233ad8fe8321b47a to your computer and use it in GitHub Desktop.

Select an option

Save clayote/d2489a7052a76fcc233ad8fe8321b47a to your computer and use it in GitHub Desktop.
Demonstration of a python-for-android bug. This script displays "OK" on desktop, but errors on Android.
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