| 1 |
from rpython.translator.backendopt import graphanalyze |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
class GilAnalyzer(graphanalyze.BoolGraphAnalyzer): |
| 8 |
|
| 9 |
def analyze_direct_call(self, graph, seen=None): |
| 10 |
try: |
| 11 |
func = graph.func |
| 12 |
except AttributeError: |
| 13 |
pass |
| 14 |
else: |
| 15 |
if getattr(func, '_gctransformer_hint_close_stack_', False): |
| 16 |
return True |
| 17 |
if getattr(func, '_transaction_break_', False): |
| 18 |
return True |
| 19 |
|
| 20 |
return graphanalyze.BoolGraphAnalyzer.analyze_direct_call( |
| 21 |
self, graph, seen) |
| 22 |
|
| 23 |
def analyze_external_call(self, op, seen=None): |
| 24 |
return False |
| 25 |
|
| 26 |
def analyze_simple_operation(self, op, graphinfo): |
| 27 |
return False |
| 28 |
|
| 29 |
def analyze(graphs, translator): |
| 30 |
gilanalyzer = GilAnalyzer(translator) |
| 31 |
for graph in graphs: |
| 32 |
func = getattr(graph, 'func', None) |
| 33 |
if func and getattr(func, '_no_release_gil_', False): |
| 34 |
if gilanalyzer.analyze_direct_call(graph): |
| 35 |
|
| 36 |
import cStringIO |
| 37 |
err = cStringIO.StringIO() |
| 38 |
import sys |
| 39 |
prev = sys.stdout |
| 40 |
try: |
| 41 |
sys.stdout = err |
| 42 |
ca = GilAnalyzer(translator) |
| 43 |
ca.verbose = True |
| 44 |
ca.analyze_direct_call(graph) |
| 45 |
sys.stdout = prev |
| 46 |
except: |
| 47 |
sys.stdout = prev |
| 48 |
|
| 49 |
|
| 50 |
raise Exception("'no_release_gil' function can release the GIL:" |
| 51 |
" %s\n%s" % (func, err.getvalue())) |
| 52 |
|
| 53 |
|