8000 gh-119247: Add macros to use PySequence_Fast safely in free-threaded build by MojoVampire · Pull Request #119315 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-119247: Add 8000 macros to use PySequence_Fast safely in free-threaded build #119315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 22, 2024
Prev Previous commit
Next Next commit
Per review, refactor extend test to extend multiple times, and reduce…
… total time to run tests (both tests combine to less than 200 ms in debug build on my laptop)
  • Loading branch information
MojoVampire committed May 22, 2024
commit 66f0e6ceb6033c20c5f6a33523eb038802923bac
26 changes: 13 additions & 13 deletions Lib/test/test_free_threading/test_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import unittest

from itertools import cycle
from threading import Thread
from threading import Event, Thread
from unittest import TestCase

from test.support import threading_helper
Expand All @@ -12,21 +12,20 @@ class TestStr(TestCase):
def test_racing_join_extend(self):
'''Test joining a string being extended by another thread'''
l = []
OBJECT_COUNT = 100_000

ITERS = 100
READERS = 10
done_event = Event()
def writer_func():
l.extend(map(str, range(OBJECT_COUNT, OBJECT_COUNT*2)))

for i in range(ITERS):
l.extend(map(str, range(i)))
l.clear()
done_event.set()
def reader_func():
while True:
count = len(l)
while not done_event.is_set():
''.join(l)
if count == OBJECT_COUNT:
break

writer = Thread(target=writer_func)
readers = []
for x in range(30):
for x in range(READERS):
reader = Thread(target=reader_func)
readers.append(reader)
reader.start()
Expand All @@ -42,7 +41,8 @@ def test_racing_join_replace(self):
strings by another thread.
'''
l = [*'abcdefg']
MAX_ORDINAL = 10_000
MAX_ORDINAL = 1_000
READERS = 20

def writer_func():
for i, c in zip(cycle(range(len(l))),
Expand All @@ -59,7 +59,7 @@ def reader_func():

writer = Thread(target=writer_func)
readers = []
for x in range(30):
for x in range(READERS):
reader = Thread(target=reader_func)
readers.append(reader)
reader.start()
Expand Down
0