Skip to content

Commit

Permalink
fix threading.local inherit for sympy
Browse files Browse the repository at this point in the history
  • Loading branch information
pmp-p committed Sep 27, 2024
1 parent 397141b commit 567f9ff
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/pygbag/support/cpythonrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,7 @@ async def main():
if ext in ("apk", "jar"):
fname = fname + ".zip"

async with platfom.fopen(source, "rb") as zipdata:
async with platform.fopen(source, "rb") as zipdata:
with open(fname, "wb") as file:
file.write(zipdata.read())
import shutil
Expand Down
10 changes: 4 additions & 6 deletions src/pygbag/support/cross/aio/gthread.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ def update(cls, saved):
pass


class Local:
pass


def local():
return Local
class local:
@classmethod
def __call__(cls):
return cls()


class Lock:
Expand Down
37 changes: 16 additions & 21 deletions test/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,24 @@
# native case

import asyncio as aio

aio.exit = False
aio.frame = 1.0/60
aio.frame = 1.0 / 60
aio.sync = False

# because threading target= does not handle generators
def synchronized(f):
def run(*argv,**kw):
def run(*argv, **kw):
global Native
gen = f(*argv,**kw)
gen = f(*argv, **kw)
while True:
deadline = time.time()+aio.frame
deadline = time.time() + aio.frame
if next(gen) is StopIteration:
return
alarm = deadline - time.time()
if alarm>0:
if alarm > 0:
time.sleep(alarm)

return run


Expand Down Expand Up @@ -76,7 +78,6 @@ def loop(self):
self.way = -self.way
self.win.blit(self.surf, (50 + (self.way * decal), 50 + (-self.way * decal)))


@synchronized
def run(self):
print(f"{self.native_id=} {self.ident=} {self.is_alive()=}")
Expand All @@ -90,6 +91,7 @@ def run(self):
# ok model
moving_svg = None


@synchronized
def color_background(win):
global moving_svg, count
Expand Down Expand Up @@ -118,6 +120,7 @@ def moving_bmp(win):
win.blit(bmp, (50 + (way * decal), 50 + (-way * decal)))
yield aio


@synchronized
def moving_png(win):
global count
Expand Down Expand Up @@ -149,31 +152,24 @@ async def main():
# still bugs in that thread model
# mbmp = Moving_bmp()


# erase and fill
(t1:=Thread(target=color_background, args=[win])).start()


(t1 := Thread(target=color_background, args=[win])).start()

moving_svg = Moving_svg()
moving_svg.win = win
print(f"{moving_svg.native_id=} {moving_svg.ident=} {moving_svg.is_alive()=}")
moving_svg.start()


# 1st object to draw
t2=Thread(target=moving_bmp, args=[win])
t2 = Thread(target=moving_bmp, args=[win])
t2.start()

# 2nd

t3=Thread(target=moving_png, args=[win])
t3 = Thread(target=moving_png, args=[win])
t3.start()


print( t1.native_id , t2.native_id , t3.native_id)


print(t1.native_id, t2.native_id, t3.native_id)

while True:
if count >= 0:
Expand All @@ -185,17 +181,16 @@ async def main():
"""
)

# if moving_svg and moving_svg.native_id:
# moving_svg.loop()
# if moving_svg and moving_svg.native_id:
# moving_svg.loop()

pygame.display.update()

if not aio.sync:
time.sleep(aio.frame) # frametime idle
time.sleep(aio.frame) # frametime idle

await asyncio.sleep(0)


if count < -60 * 30: # about * seconds
print("exit game loop")
break
Expand Down

0 comments on commit 567f9ff

Please sign in to comment.