Skip to content

Commit ac9245a

Browse files
albanDsoumith
authored andcommitted
import numpy before setting dlopen flags (#928)
1 parent 60736bd commit ac9245a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

torch/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@
3131
# automatically filled by the dynamic loader.
3232
import os as _dl_flags
3333

34+
# if we have numpy, it *must* be imported before the call to setdlopenflags()
35+
# or there is risk that later c modules will segfault when importing numpy
36+
try:
37+
import numpy as np
38+
except:
39+
pass
40+
3441
# first check if the os package has the required flags
3542
if not hasattr(_dl_flags, 'RTLD_GLOBAL') or not hasattr(_dl_flags, 'RTLD_NOW'):
3643
try:

0 commit comments

Comments
 (0)