Commit fecd8d52 authored by Jason Madden's avatar Jason Madden

Under PyPy, make the main greenlet look like the MainThread. This fixes many...

Under PyPy, make the main greenlet look like the MainThread. This fixes many of the threading related tests.

After:

18/123 tests failed in 03:32

14/123 expected failures

4/123 unexpected failures
parent f599b34e
......@@ -14,7 +14,7 @@ import threading as __threading__
_DummyThread_ = __threading__._DummyThread
from gevent.local import local
from gevent.thread import start_new_thread as _start_new_thread, allocate_lock as _allocate_lock, get_ident as _get_ident
from gevent.hub import sleep as _sleep, getcurrent
from gevent.hub import sleep as _sleep, getcurrent, PYPY
Lock = _allocate_lock
......@@ -35,3 +35,12 @@ class _DummyThread(_DummyThread_):
def _Thread__stop(self):
pass
if PYPY:
# Make sure the MainThread can be found by our current greenlet ID,
# otherwise we get a new DummyThread, which cannot be joined.
# Fixes tests in test_threading_2
if _get_ident() not in __threading__._active and len(__threading__._active) == 1:
k,v = __threading__._active.items()[0]
del __threading__._active[k]
__threading__._active[_get_ident()] = v
......@@ -120,9 +120,11 @@ class ThreadTests(unittest.TestCase):
for i in range(NUMTASKS):
t = TestThread("<thread %d>" % i, self, sema, mutex, numrunning)
threads.append(t)
t.daemon = False # Under PYPY we get daemon by default?
if hasattr(t, 'ident'):
self.failUnlessEqual(t.ident, None)
self.assert_(re.match('<TestThread\(.*, initial\)>', repr(t)))
self.assertFalse(t.daemon)
self.assert_(re.match(r'<TestThread\(.*, initial\)>', repr(t)))
t.start()
if verbose:
......@@ -133,7 +135,7 @@ class ThreadTests(unittest.TestCase):
if hasattr(t, 'ident'):
self.failIfEqual(t.ident, 0)
self.assertFalse(t.ident is None)
self.assert_(re.match('<TestThread\(.*, \w+ -?\d+\)>', repr(t)))
self.assert_(re.match(r'<TestThread\(.*, \w+ -?\d+\)>', repr(t)))
if verbose:
print('all tasks done')
self.assertEqual(numrunning.get(), 0)
......@@ -292,7 +294,8 @@ class ThreadTests(unittest.TestCase):
# example.
try:
import ctypes
except ImportError:
getattr(ctypes, 'pythonapi') # not available on PyPy
except (ImportError,AttributeError):
if verbose:
print("test_finalize_with_runnning_thread can't import ctypes")
return # can't do anything
......@@ -413,7 +416,6 @@ class ThreadJoinOnShutdown(unittest.TestCase):
script = """if 1:
%s
import sys, os, time, threading
# a thread, which waits for the main program to terminate
def joiningfunc(mainthread):
mainthread.join()
......
......@@ -75,8 +75,6 @@ if PYPY:
'test_socket.py',
# No idea!
'test_threading_2.py',
'test_threading.py',
'test__pywsgi.py',
'test__backdoor.py',
'test__refcount.py',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment