Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_capi.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | cd8d3c2d3bce |
| children | c6ca87fbea39 |
| rev | line source |
|---|---|
|
16447
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
16413
diff
changeset
|
1 # Run the _testcapi module tests (tests for the Python/C API): by defn, |
|
17495
e526d9248965
Fix typo in comment (the module is now called _testcapi, not _test).
Guido van Rossum <guido@python.org>
parents:
16447
diff
changeset
|
2 # these are all functions _testcapi exports whose name begins with 'test_'. |
|
16413
8819867f14ef
Patch derived from Trent's 101162: a Python/C API testing framework.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
3 |
|
50865
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
4 from __future__ import with_statement |
|
34666
4812f6a7f735
Revert previous checkin on getargs 'L' code. Try to convert all
Martin v. Löwis <martin@v.loewis.de>
parents:
34652
diff
changeset
|
5 import sys |
|
50675
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
6 import time |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
7 import random |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
8 import unittest |
|
24364
aa0d2d51fbde
Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents:
17495
diff
changeset
|
9 from test import test_support |
|
61040
967f7bc2dcc8
Issue #7449, part 7: simplify threading detection in test_capi
Victor Stinner <victor.stinner@haypocalc.com>
parents:
58669
diff
changeset
|
10 try: |
|
967f7bc2dcc8
Issue #7449, part 7: simplify threading detection in test_capi
Victor Stinner <victor.stinner@haypocalc.com>
parents:
58669
diff
changeset
|
11 import threading |
|
967f7bc2dcc8
Issue #7449, part 7: simplify threading detection in test_capi
Victor Stinner <victor.stinner@haypocalc.com>
parents:
58669
diff
changeset
|
12 except ImportError: |
|
967f7bc2dcc8
Issue #7449, part 7: simplify threading detection in test_capi
Victor Stinner <victor.stinner@haypocalc.com>
parents:
58669
diff
changeset
|
13 threading = None |
|
16447
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
16413
diff
changeset
|
14 import _testcapi |
|
16413
8819867f14ef
Patch derived from Trent's 101162: a Python/C API testing framework.
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
15 |
|
61040
967f7bc2dcc8
Issue #7449, part 7: simplify threading detection in test_capi
Victor Stinner <victor.stinner@haypocalc.com>
parents:
58669
diff
changeset
|
16 @unittest.skipUnless(threading, 'Threading required for this test.') |
|
50675
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
17 class TestPendingCalls(unittest.TestCase): |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
18 |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
19 def pendingcalls_submit(self, l, n): |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
20 def callback(): |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
21 #this function can be interrupted by thread switching so let's |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
22 #use an atomic operation |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
23 l.append(None) |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
24 |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
25 for i in range(n): |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
26 time.sleep(random.random()*0.02) #0.01 secs on average |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
27 #try submitting callback until successful. |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
28 #rely on regular interrupt to flush queue if we are |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
29 #unsuccessful. |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
30 while True: |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
31 if _testcapi._pending_threadfunc(callback): |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
32 break; |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
33 |
|
50865
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
34 def pendingcalls_wait(self, l, n, context = None): |
|
50675
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
35 #now, stick around until l[0] has grown to 10 |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
36 count = 0; |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
37 while len(l) != n: |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
38 #this busy loop is where we expect to be interrupted to |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
39 #run our callbacks. Note that callbacks are only run on the |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
40 #main thread |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
41 if False and test_support.verbose: |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
42 print "(%i)"%(len(l),), |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
43 for i in xrange(1000): |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
44 a = i*i |
|
50865
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
45 if context and not context.event.is_set(): |
|
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
46 continue |
|
50675
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
47 count += 1 |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
50865
diff
changeset
|
48 self.assertTrue(count < 10000, |
|
50675
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
49 "timeout waiting for %i callbacks, got %i"%(n, len(l))) |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
50 if False and test_support.verbose: |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
51 print "(%i)"%(len(l),) |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
52 |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
53 def test_pendingcalls_threaded(self): |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
54 #do every callback on a separate thread |
|
50865
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
55 n = 32 #total callbacks |
|
50675
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
56 threads = [] |
|
50865
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
57 class foo(object):pass |
|
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
58 context = foo() |
|
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
59 context.l = [] |
|
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
60 context.n = 2 #submits per thread |
|
58669
ff040880d1be
#7092: Silence more py3k warnings. Patch by Florent Xicluna.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58198
diff
changeset
|
61 context.nThreads = n // context.n |
|
50865
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
62 context.nFinished = 0 |
|
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
63 context.lock = threading.Lock() |
|
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
64 context.event = threading.Event() |
|
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
65 |
|
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
66 for i in range(context.nThreads): |
|
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
67 t = threading.Thread(target=self.pendingcalls_thread, args = (context,)) |
|
50675
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
68 t.start() |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
69 threads.append(t) |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
70 |
|
50865
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
71 self.pendingcalls_wait(context.l, n, context) |
|
50675
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
72 |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
73 for t in threads: |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
74 t.join() |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
75 |
|
50865
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
76 def pendingcalls_thread(self, context): |
|
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
77 try: |
|
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
78 self.pendingcalls_submit(context.l, context.n) |
|
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
79 finally: |
|
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
80 with context.lock: |
|
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
81 context.nFinished += 1 |
|
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
82 nFinished = context.nFinished |
|
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
83 if False and test_support.verbose: |
|
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
84 print "finished threads: ", nFinished |
|
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
85 if nFinished == context.nThreads: |
|
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
86 context.event.set() |
|
9bbb9ac061c0
issue 4293: make test_capi.py more robutst, it times out on some platforms, presumably waiting for threads. Lower the thread count to 16.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
50675
diff
changeset
|
87 |
|
50675
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
88 def test_pendingcalls_non_threaded(self): |
|
68588
cd8d3c2d3bce
#11565: Fix several typos. Patch by Piotr Kasprzyk.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
61040
diff
changeset
|
89 #again, just using the main thread, likely they will all be dispatched at |
|
50675
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
90 #once. It is ok to ask for too many, because we loop until we find a slot. |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
91 #the loop can be interrupted to dispatch. |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
92 #there are only 32 dispatch slots, so we go for twice that! |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
93 l = [] |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
94 n = 64 |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
95 self.pendingcalls_submit(l, n) |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
96 self.pendingcalls_wait(l, n) |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
97 |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
98 |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
99 def test_main(): |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24364
diff
changeset
|
100 |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
101 for name in dir(_testcapi): |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
102 if name.startswith('test_'): |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
103 test = getattr(_testcapi, name) |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
104 if test_support.verbose: |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
105 print "internal", name |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
106 try: |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
107 test() |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
108 except _testcapi.error: |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
109 raise test_support.TestFailed, sys.exc_info()[1] |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24364
diff
changeset
|
110 |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
111 # some extra thread-state tests driven via _testcapi |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
112 def TestThreadState(): |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
113 if test_support.verbose: |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
114 print "auto-thread-state" |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
115 |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
116 idents = [] |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24364
diff
changeset
|
117 |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
118 def callback(): |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
119 idents.append(thread.get_ident()) |
|
28774
c9bee11eaa8b
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28694
diff
changeset
|
120 |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
121 _testcapi._test_thread_state(callback) |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
122 a = b = callback |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
123 time.sleep(1) |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
124 # Check our main thread is in the list exactly 3 times. |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
125 if idents.count(thread.get_ident()) != 3: |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
126 raise test_support.TestFailed, \ |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
127 "Couldn't find main thread correctly in the list" |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24364
diff
changeset
|
128 |
|
61040
967f7bc2dcc8
Issue #7449, part 7: simplify threading detection in test_capi
Victor Stinner <victor.stinner@haypocalc.com>
parents:
58669
diff
changeset
|
129 if threading: |
|
46358
382d5ea17d78
Issue2564: Prevent a hang in "import test.autotest", which runs the entire test
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
37117
diff
changeset
|
130 import thread |
|
382d5ea17d78
Issue2564: Prevent a hang in "import test.autotest", which runs the entire test
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
37117
diff
changeset
|
131 import time |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
132 TestThreadState() |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
133 t=threading.Thread(target=TestThreadState) |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
134 t.start() |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
135 t.join() |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
136 |
|
50675
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
137 test_support.run_unittest(TestPendingCalls) |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
138 |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
139 if __name__ == "__main__": |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
140 test_main() |
