提交 2f197df7 authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Reload the lazylinker lib instead of recompiling it on every import.

This is especially important under Windows, where one cannot overwrite a library currently in use.
上级 2eed13da
import os import os, sys
import theano import theano
from theano import config from theano import config
from theano.gof.compilelock import get_lock, release_lock from theano.gof.compilelock import get_lock, release_lock
from theano.gof import cmodule from theano.gof import cmodule
get_lock() # Ensure the compiledir is in `sys.path` to be able to reload an existing
# precompiled library.
if config.compiledir not in sys.path:
sys.path.append(config.compiledir)
try: try:
import lazylinker_ext
except ImportError:
get_lock()
try:
# Maybe someone else already finished compiling it while we were
# waiting for the lock?
try:
import lazylinker_ext
except ImportError:
dirname = 'lazylinker_ext' dirname = 'lazylinker_ext'
cfile = os.path.join(theano.__path__[0], 'gof', 'lazylinker_c.c') cfile = os.path.join(theano.__path__[0], 'gof', 'lazylinker_c.c')
code = open(cfile).read() code = open(cfile).read()
...@@ -13,8 +27,8 @@ try: ...@@ -13,8 +27,8 @@ try:
if not os.path.exists(loc): if not os.path.exists(loc):
os.mkdir(loc) os.mkdir(loc)
cmodule.gcc_module_compile_str(dirname, code, location=loc) cmodule.gcc_module_compile_str(dirname, code, location=loc)
from lazylinker_ext.lazylinker_ext import * finally:
finally:
# Release lock on compilation directory. # Release lock on compilation directory.
release_lock() release_lock()
from lazylinker_ext.lazylinker_ext import *
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论