result = []
error = []
// run on thread which have large stack
def worker():
try:
generator = get_generator(backend)
// Graph is transformed by backend-specific optimization
c_graph = copy.deepcopy(graph)
// some optimize rule work even when OPTIMIZE=0
opt_graph, _ = GeneralOptimizeRule().optimize(c_graph)
result.append(generator(opt_graph, **kwargs))
except Exception as ex:
error.append(ex)
if flags.NO_WORKER_THREAD:
worker()
else:
import threading
sys.setrecursionlimit(16384)
threading.stack_size(64 * 1024 * 1024)
t = threading.Thread(target=worker)
t.start()
t.join()
if len(error) > 0:
raise error[0]
return result[0]