← Back to team overview

dolfin team mailing list archive

Fwd: [Branch ~dolfin-core/dolfin/main] Rev 5566: Block import of PyTrilinos after import of dolfin

 

I've reverted this change becomes it only helps in a special case and
doesn't resolve the underlying issue.

If PyTrilinos is imported, and a PETSc-based object is created, then a
program emit errors irrespective of the import order because the
PyTrilinos atexit function is always called before the PETScFoo destructor.

Garth



-------- Original Message --------
Subject: [Branch ~dolfin-core/dolfin/main] Rev 5566: Block import of
PyTrilinos after import of dolfin
Date: Sun, 23 Jan 2011 06:59:28 -0000
From: noreply@xxxxxxxxxxxxx
Reply-To: noreply@xxxxxxxxxxxxx
To: Garth Wells <gnw20@xxxxxxxxx>

------------------------------------------------------------
revno: 5566
committer: Johan Hake <hake.dev@xxxxxxxxx>
branch nick: dolfin
timestamp: Sat 2011-01-22 22:56:51 -0800
message:
  Block import of PyTrilinos after import of dolfin
  (from Joachim Haga)
added:
  site-packages/dolfin/importhandler/blockimport.py
modified:
  site-packages/dolfin/importhandler/__init__.py
  site-packages/dolfin/importhandler/dynamicloadmpi.py


--
lp:dolfin
https://code.launchpad.net/~dolfin-core/dolfin/main

Your team DOLFIN Core Team is subscribed to branch lp:dolfin.
To unsubscribe from this branch go to
https://code.launchpad.net/~dolfin-core/dolfin/main/+edit-subscription

=== modified file 'site-packages/dolfin/importhandler/__init__.py'
--- site-packages/dolfin/importhandler/__init__.py	2011-01-22 22:11:04 +0000
+++ site-packages/dolfin/importhandler/__init__.py	2011-01-23 06:56:51 +0000
@@ -1,6 +1,3 @@
 """The importhandler module of dolfin"""
-try:
-    import dolfin.importhandler.dynamicloadmpi
-except OSError:
-    pass
-
+import dynamicloadmpi
+import blockimport

=== added file 'site-packages/dolfin/importhandler/blockimport.py'
--- site-packages/dolfin/importhandler/blockimport.py	1970-01-01 00:00:00 +0000
+++ site-packages/dolfin/importhandler/blockimport.py	2011-01-23 06:56:51 +0000
@@ -0,0 +1,22 @@
+"""Handles blocking of import of modules"""
+
+__author__ = "Joachim Haga <jobh@xxxxxxxxxxxx>"
+__date__ = "2011-01-22 -- 2011-01-22"
+__copyright__ = "Copyright (C) 2007-2008 Joachim Haga"
+__license__  = "GNU LGPL Version 2.1"
+
+import sys
+from dolfin.cpp import error
+
+def block_import_after_dolfin(name, reason):
+    prefix = name+'.'
+    class Importer(object):
+        def find_module(self, fullname, path=None):
+            if fullname == name or fullname.startswith(prefix):
+                if not name in sys.modules:
+                    error('%s must be imported before dolfin (see %s)'%(name, reason))
+                return None
+    sys.meta_path.append(Importer())
+
+block_import_after_dolfin('PyTrilinos', \
+                          'https://bugs.launchpad.net/dolfin/+bug/705401')

=== modified file 'site-packages/dolfin/importhandler/dynamicloadmpi.py'
--- site-packages/dolfin/importhandler/dynamicloadmpi.py	2011-01-22 22:11:04 +0000
+++ site-packages/dolfin/importhandler/dynamicloadmpi.py	2011-01-23 06:56:51 +0000
@@ -13,4 +13,7 @@
 else:
     libmpi = 'libmpi.so'
 
-ctypes.CDLL(libmpi, ctypes.RTLD_GLOBAL)
+try:
+    ctypes.CDLL(libmpi, ctypes.RTLD_GLOBAL)
+except OSError:
+    pass