What could cause a python module to be imported twice? -


as far understand, python module never imported twice, i.e. code in module gets executed first time imported. subsequent import statements add module scope of import.

i have module called "tiledconvc3d.py" seems imported multiple times though. use pdb print stack @ top of code module.

here end of stack trace first time module executed:

file "<anonymized>/python_modules/theano/theano/gof/cmodule.py", line 328, in refresh   key = cpickle.load(open(key_pkl, 'rb')) file "<anonymized>/ops/tiledconvg3d.py", line 565, in <module>   import tiledconvc3d file "<anonymized>/ops/tiledconvc3d.py", line 18, in <module>   pdb.traceback.print_stack() 

it goes on executed several more times. however, complete stack trace second time called not show calls reload, these executions should not occurring:

file "sup_train_conj_grad.py", line 103, in <module>   dataset = config.get_dataset(dataset_node) file "<anonymized>/config.py", line 279, in get_dataset   datasets import newwiskott file "<anonymized>/datasets/newwiskott.py", line 16, in <module>   normalizer_train = video.contrastnormalizer3d(sigma, global_per_frame = false, input_is_5d = true) file "<anonymized>/util/video.py", line 204, in __init__   self.f = theano.function([input],output) file "<anonymized>/python_modules/theano/theano/compile/function.py", line 105, in function   allow_input_downcast=allow_input_downcast) file "<anonymized>/python_modules/theano/theano/compile/pfunc.py", line 270, in pfunc   accept_inplace=accept_inplace, name=name) file "<anonymized>/python_modules/theano/theano/compile/function_module.py", line 1105, in orig_function   fn = maker(inputs, outputs, mode, accept_inplace = accept_inplace).create(defaults) file "/u/goodfeli/python_modules/theano/theano/compile/function_module.py", line 982, in create   _fn, _i, _o = self.linker.make_thunk(input_storage = input_storage_lists) file "<anonymized>/python_modules/theano/theano/gof/link.py", line 321, in make_thunk   output_storage = output_storage)[:3] file "<anonymized>/python_modules/theano/theano/gof/cc.py", line 1178, in make_all   output_storage = node_output_storage) file "<anonymized>/python_modules/theano/theano/gof/cc.py", line 774, in make_thunk   cthunk, in_storage, out_storage, error_storage = self.__compile__(input_storage, output_storage) file "<anonymized>/python_modules/theano/theano/gof/cc.py", line 723, in __compile__   output_storage) file "<anonymized>/python_modules/theano/theano/gof/cc.py", line 1037, in cthunk_factory   module = get_module_cache().module_from_key(key=key, fn=self.compile_cmodule) file "<anonymized>/python_modules/theano/theano/gof/cc.py", line 59, in get_module_cache   return cmodule.get_module_cache(config.compiledir) file "<anonymized>/python_modules/theano/theano/gof/cmodule.py", line 576, in get_module_cache   _module_cache = modulecache(dirname, force_fresh=force_fresh) file "<anonymized>/python_modules/theano/theano/gof/cmodule.py", line 268, in __init__   self.refresh() file "<anonymized>/python_modules/theano/theano/gof/cmodule.py", line 326, in refresh   key = cpickle.load(open(key_pkl, 'rb')) file "<anonymized>/ops/tiledconvv3d.py", line 504, in <module>   import tiledconvg3d file "<anonymized>/ops/tiledconvg3d.py", line 565, in <module>   import tiledconvc3d file "<anonymized>/ops/tiledconvc3d.py", line 22, in <module>   pdb.traceback.print_stack() 

moreover, check id of __builtin__.__import__ . @ start of main script, import __builtin__ , print id(__builtin__.__import__) before doing other imports. print id(__builtin__.import__) inside module being imported multiple times, , value of id not change.

are there other mechanisms besides calling reload , overriding __builtin__.__import__ explain module getting loaded multiple times?

a python module can imported twice if module found twice in path. example, project laid out so:

  • src/
    • package1/
      • spam.py
      • eggs.py

suppose pythonpath (sys.path) includes src , src/package1:

pythonpath=/path/to/src:/path/to/src/package1 

if that's case, can import same module twice this:

from package1 import spam import spam 

and python think different modules. what's going on?

also, per discussion below (for users searching question), way module can imported twice if there exception midway through first import. example, if spam imports eggs, importing eggs results in exception inside module, can imported again.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -