提交 27f62bf3 authored 作者: Frederic's avatar Frederic

When loading cutils_ext module, put the path at the start of sys.path to prevent conflict.

close gh-728
上级 1ada610b
...@@ -56,32 +56,33 @@ def compile_cutils(): ...@@ -56,32 +56,33 @@ def compile_cutils():
cmodule.GCC_compiler.compile_str('cutils_ext', code, location=loc, cmodule.GCC_compiler.compile_str('cutils_ext', code, location=loc,
preargs=args) preargs=args)
try: try:
# If we load a previously-compiled version, config.compiledir should try:
# be in sys.path. # Must be at the beginning to ensure no conflict with other project
if config.compiledir not in sys.path: # that would use the same module name.
sys.path.insert(0, config.compiledir) sys.path.insert(0, config.compiledir)
from cutils_ext.cutils_ext import * from cutils_ext.cutils_ext import *
except ImportError: except ImportError:
import cmodule import cmodule
get_lock() get_lock()
# Ensure no-one else is currently modifying the content of the compilation # Ensure no-one else is currently modifying the content of the compilation
# directory. This is important to prevent multiple processes from trying to # directory. This is important to prevent multiple processes from trying to
# compile the cutils_ext module simultaneously. # compile the cutils_ext module simultaneously.
try:
try: try:
# We must retry to import it as some other processs could try:
# have been compiling it between the first failed import # We must retry to import it as some other processs could
# and when we receive the lock # have been compiling it between the first failed import
from cutils_ext.cutils_ext import * # and when we receive the lock
except ImportError: from cutils_ext.cutils_ext import *
import cmodule except ImportError:
import cmodule
compile_cutils() compile_cutils()
from cutils_ext.cutils_ext import * from cutils_ext.cutils_ext import *
finally: finally:
# Release lock on compilation directory. # Release lock on compilation directory.
release_lock() release_lock()
finally:
del sys.path[0]
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论