Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_capi.py @ 54294:dba767bc3155 legacy-trunk
remove mention of old ctypes version
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 23 May 2009 20:59:09 +0000 |
| parents | 9bbb9ac061c0 |
| children | 6768b2350c57 |
| 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 |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
9 import threading |
|
24364
aa0d2d51fbde
Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents:
17495
diff
changeset
|
10 from test import test_support |
|
16447
ac52d3727867
Renamed _testXXX to _testcapiXXX. Jack is my hero -- good call!
Tim Peters <tim.peters@gmail.com>
parents:
16413
diff
changeset
|
11 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
|
12 |
|
50675
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
13 class TestPendingCalls(unittest.TestCase): |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
14 |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
15 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
|
16 def callback(): |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
17 #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
|
18 #use an atomic operation |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
19 l.append(None) |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
20 |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
21 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
|
22 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
|
23 #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
|
24 #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
|
25 #unsuccessful. |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
26 while True: |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
27 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
|
28 break; |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
29 |
|
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
|
30 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
|
31 #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
|
32 count = 0; |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
33 while len(l) != n: |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
34 #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
|
35 #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
|
36 #main thread |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
37 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
|
38 print "(%i)"%(len(l),), |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
39 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
|
40 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
|
41 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
|
42 continue |
|
50675
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
43 count += 1 |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
44 self.failUnless(count < 10000, |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
45 "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
|
46 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
|
47 print "(%i)"%(len(l),) |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
48 |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
49 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
|
50 |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
51 #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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 context.n = 2 #submits per thread |
|
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.nThreads = n / 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
|
59 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
|
60 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
|
61 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
|
62 |
|
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 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
|
64 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
|
65 t.start() |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
66 threads.append(t) |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
67 |
|
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
|
68 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
|
69 |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
70 for t in threads: |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
71 t.join() |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
72 |
|
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
|
73 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
|
74 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 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
|
83 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
|
84 |
|
50675
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
85 def test_pendingcalls_non_threaded(self): |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
86 #again, just using the main thread, likely they will all be dispathced at |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
87 #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
|
88 #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
|
89 #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
|
90 l = [] |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
91 n = 64 |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
92 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
|
93 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
|
94 |
|
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
95 |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
96 def test_main(): |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24364
diff
changeset
|
97 |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
98 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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 try: |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
104 test() |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
105 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
|
106 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
|
107 |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
108 # 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
|
109 def TestThreadState(): |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
110 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
|
111 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
|
112 |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
113 idents = [] |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24364
diff
changeset
|
114 |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
115 def callback(): |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
116 idents.append(thread.get_ident()) |
|
28774
c9bee11eaa8b
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28694
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 _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
|
119 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
|
120 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
|
121 # 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
|
122 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
|
123 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
|
124 "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
|
125 |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
126 try: |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
127 _testcapi._test_thread_state |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
128 have_thread_state = True |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
129 except AttributeError: |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
130 have_thread_state = False |
|
28774
c9bee11eaa8b
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28694
diff
changeset
|
131 |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
132 if have_thread_state: |
|
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
|
133 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
|
134 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
|
135 TestThreadState() |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
136 import threading |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
137 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
|
138 t.start() |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
139 t.join() |
|
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
140 |
|
50675
e6f55c9ec3d0
Issue 4293: Make Py_AddPendingCall() thread safe
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
46358
diff
changeset
|
141 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
|
142 |
|
37117
f7993dc6bf26
Try to repair at least one segfault on the Mac buildbot,
Tim Peters <tim.peters@gmail.com>
parents:
34666
diff
changeset
|
143 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
|
144 test_main() |
