Debian Codegraph @

rpython/translator/backendopt/gilanalysis.py

raw symbols SCIP
1 from rpython.translator.backendopt import graphanalyze
2
3 # This is not an optimization. It checks for possible releases of the
4 # GIL in all graphs starting from rgc.no_release_gil.
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 # 'no_release_gil' function can release the gil
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) # print the "traceback" here
45 sys.stdout = prev
46 except:
47 sys.stdout = prev
48 # ^^^ for the dump of which operation in which graph actually
49 # causes it to return True
50 raise Exception("'no_release_gil' function can release the GIL:"
51 " %s\n%s" % (func, err.getvalue()))
52
53