profile nogil functions: warning instead of error
authorLisandro Dalcin <dalcinl@gmail.com>
Fri, 1 Apr 2011 01:08:58 +0000 (22:08 -0300)
committerLisandro Dalcin <dalcinl@gmail.com>
Fri, 1 Apr 2011 01:08:58 +0000 (22:08 -0300)
Cython/Compiler/Nodes.py
tests/run/pstats_profile_test.pyx

index 7b91add2c5c0f4f2401b00cc5ed049345b5f2ae7..358c067f2b728becd8802d8a2126750897e19c87 100644 (file)
@@ -1252,9 +1252,10 @@ class FuncDefNode(StatNode, BlockNode):
                     preprocessor_guard = None
 
         profile = code.globalstate.directives['profile']
+        if profile and lenv.nogil:
+            warning(self.pos, "Cannot profile nogil function.", 1)
+            profile = False
         if profile:
-            if lenv.nogil:
-                error(self.pos, "Cannot profile nogil function.")
             code.globalstate.use_utility_code(profile_utility_code)
 
         # Generate C code for header and body of function
index f9d2d5c3574599b833976d81018a4da0cfbe4ced..e9edee9684eecd52bd0aea9dc85ba3c14bd4f4b3 100644 (file)
@@ -20,6 +20,23 @@ __doc__ = u"""
     KeyError: 'f_noprof'
     >>> short_stats['f_raise']
     100
+
+    >>> short_stats['withgil_prof']
+    100
+    >>> short_stats['withgil_noprof']
+    Traceback (most recent call last):
+    ...
+    KeyError: 'withgil_noprof'
+
+    >>> short_stats['nogil_prof']
+    Traceback (most recent call last):
+    ...
+    KeyError: 'nogil_prof'
+    >>> short_stats['nogil_noprof']
+    Traceback (most recent call last):
+    ...
+    KeyError: 'nogil_noprof'
+
     >>> try:
     ...    os.unlink(statsfile)
     ... except:
@@ -43,6 +60,10 @@ def test_profile(long N):
         n += f_inline(i)
         n += f_inline_prof(i)
         n += f_noprof(i)
+        n += nogil_noprof(i)
+        n += nogil_prof(i)
+        n += withgil_noprof(i)
+        n += withgil_prof(i)
         try:
             n += f_raise(i+2)
         except RuntimeError:
@@ -68,3 +89,18 @@ cdef int f_noprof(long a):
 
 cdef long f_raise(long) except -2:
     raise RuntimeError
+
+@cython.profile(False)
+cdef int withgil_noprof(long a) with gil:
+    return (a)
+@cython.profile(True)
+cdef int withgil_prof(long a) with gil:
+    return (a)
+
+@cython.profile(False)
+cdef int nogil_noprof(long a) nogil:
+    return a
+@cython.profile(True)
+cdef int nogil_prof(long a) nogil:
+    return a
+