portdbapi: use global_event_loop when safe
authorZac Medico <zmedico@gentoo.org>
Thu, 3 Jan 2013 22:42:41 +0000 (14:42 -0800)
committerZac Medico <zmedico@gentoo.org>
Thu, 3 Jan 2013 22:42:41 +0000 (14:42 -0800)
pym/portage/dbapi/porttree.py

index 35f4e2d098160e4dad5b07c21dda47c2ea93bfcf..ebb1be87a2b76a104329ab0fb337a7c7f83eb697 100644 (file)
@@ -34,6 +34,7 @@ from portage import _encodings
 from portage import _unicode_encode
 from portage import OrderedDict
 from portage.util._eventloop.EventLoop import EventLoop
+from portage.util._eventloop.global_event_loop import global_event_loop
 from _emerge.EbuildMetadataPhase import EbuildMetadataPhase
 
 import os as _os
@@ -96,7 +97,6 @@ class portdbapi(dbapi):
                # this purpose because doebuild makes many changes to the config
                # instance that is passed in.
                self.doebuild_settings = config(clone=self.settings)
-               self._event_loop = EventLoop(main=False)
                self.depcachedir = os.path.realpath(self.settings.depcachedir)
                
                if os.environ.get("SANDBOX_ON") == "1":
@@ -195,6 +195,17 @@ class portdbapi(dbapi):
                self._aux_cache = {}
                self._broken_ebuilds = set()
 
+       @property
+       def _event_loop(self):
+               if portage._internal_warnings:
+                       # For internal portage usage, the global_event_loop is safe.
+                       return global_event_loop()
+               else:
+                       # For external API consumers, use a local EventLoop, since
+                       # we don't want to assume that it's safe to override the
+                       # global SIGCHLD handler.
+                       return EventLoop(main=False)
+
        def _create_pregen_cache(self, tree):
                conf = self.repositories.get_repo_for_location(tree)
                cache = conf.get_pregenerated_cache(