Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r83768:e623b2b8996e
Date: 2016-04-19 12:42 +0200
http://bitbucket.org/pypy/pypy/changeset/e623b2b8996e/

Log:    PyEval_ThreadsInitialized(): don't return always 1

diff --git a/pypy/module/cpyext/pystate.py b/pypy/module/cpyext/pystate.py
--- a/pypy/module/cpyext/pystate.py
+++ b/pypy/module/cpyext/pystate.py
@@ -52,7 +52,8 @@
 def PyEval_ThreadsInitialized(space):
     if not space.config.translation.thread:
         return 0
-    return 1
+    from pypy.module.thread import os_thread
+    return int(os_thread.threads_initialized(space))
 
 # XXX: might be generally useful
 def encapsulator(T, flavor='raw', dealloc=None):
diff --git a/pypy/module/cpyext/test/test_pystate.py 
b/pypy/module/cpyext/test/test_pystate.py
--- a/pypy/module/cpyext/test/test_pystate.py
+++ b/pypy/module/cpyext/test/test_pystate.py
@@ -112,6 +112,16 @@
         res = module.bounce()
         assert res == 3
 
+    def test_threadsinitialized(self):
+        module = self.import_extension('foo', [
+                ("test", "METH_NOARGS",
+                 """
+                 return PyInt_FromLong(PyEval_ThreadsInitialized());
+                 """),
+                ])
+        res = module.test()
+        print "got", res
+        assert res in (0, 1)
 
 
 class TestInterpreterState(BaseApiTest):
diff --git a/pypy/module/thread/gil.py b/pypy/module/thread/gil.py
--- a/pypy/module/thread/gil.py
+++ b/pypy/module/thread/gil.py
@@ -34,6 +34,9 @@
             result = False      # already set up
         return result
 
+    def threads_initialized(self):
+        return self.gil_ready
+
     ## def reinit_threads(self, space):
     ##     "Called in the child process after a fork()"
     ##     OSThreadLocals.reinit_threads(self, space)
diff --git a/pypy/module/thread/os_thread.py b/pypy/module/thread/os_thread.py
--- a/pypy/module/thread/os_thread.py
+++ b/pypy/module/thread/os_thread.py
@@ -148,6 +148,9 @@
     space.threadlocals.setup_threads(space)
     bootstrapper.setup(space)
 
+def threads_initialized(space):
+    return space.threadlocals.threads_initialized()
+
 
 def reinit_threads(space):
     "Called in the child process after a fork()"
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to