forked from pyscf/mpi4pyscf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
41 lines (36 loc) · 1.18 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Must import every submodule before suspending the slave processes
import pyscf
from distutils.version import LooseVersion
assert(LooseVersion(pyscf.__version__) >= LooseVersion('1.6'))
assert(LooseVersion(pyscf.__version__) < LooseVersion('1.7'))
del(LooseVersion)
from . import lib
from . import pbc
from . import cc
from . import mp
from . import scf
from . import dft
# NOTE: suspend all slave processes at last
from .tools import mpi
if not mpi.pool.is_master():
import sys
import imp
import traceback
# Handle global import lock for multithreading, see
# http://stackoverflow.com/questions/12389526/import-inside-of-a-python-thread
# https://docs.python.org/3.4/library/imp.html#imp.lock_held
# Global import lock affects the ctypes module. It leads to deadlock when
# ctypes function is called in new threads created by threading module.
if sys.version_info < (3,4):
if imp.lock_held():
imp.release_lock()
try:
mpi.pool.wait()
except BaseException as err:
traceback.print_exc(err)
mpi.comm.Abort()
exit(1)
if sys.version_info < (3,4):
if not imp.lock_held():
imp.acquire_lock()
exit(0)