From b1637bc9d66bbee3a036dae968ef05aa4d4ac15d Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 3 Jan 2013 18:23:42 -0800 Subject: [PATCH] portage._internal_caller: use global_event_loop It's more efficient to use global_event_loop than a local EventLoop instance, so do that when we know it's safe. --- pym/_emerge/PollScheduler.py | 6 ++++-- pym/portage/dbapi/vartree.py | 15 ++++++++++----- pym/portage/package/ebuild/_spawn_nofetch.py | 6 ++++-- pym/portage/package/ebuild/doebuild.py | 20 ++++++++++++++------ 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/pym/_emerge/PollScheduler.py b/pym/_emerge/PollScheduler.py index 220394b41..b118ac157 100644 --- a/pym/_emerge/PollScheduler.py +++ b/pym/_emerge/PollScheduler.py @@ -1,4 +1,4 @@ -# Copyright 1999-2012 Gentoo Foundation +# Copyright 1999-2013 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 try: @@ -6,6 +6,7 @@ try: except ImportError: import dummy_threading as threading +import portage from portage.util._async.SchedulerInterface import SchedulerInterface from portage.util._eventloop.EventLoop import EventLoop from portage.util._eventloop.global_event_loop import global_event_loop @@ -35,7 +36,8 @@ class PollScheduler(object): elif main: self._event_loop = global_event_loop() else: - self._event_loop = EventLoop(main=False) + self._event_loop = (portage._internal_caller and + global_event_loop() or EventLoop(main=False)) self._sched_iface = SchedulerInterface(self._event_loop, is_background=self._is_background) diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index 7a930e553..beff5bdc6 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -1,4 +1,4 @@ -# Copyright 1998-2012 Gentoo Foundation +# Copyright 1998-2013 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 __all__ = [ @@ -34,6 +34,7 @@ portage.proxy.lazyimport.lazyimport(globals(), 'portage.util._dyn_libs.LinkageMapELF:LinkageMapELF@LinkageMap', 'portage.util._async.SchedulerInterface:SchedulerInterface', 'portage.util._eventloop.EventLoop:EventLoop', + 'portage.util._eventloop.global_event_loop:global_event_loop', 'portage.versions:best,catpkgsplit,catsplit,cpv_getkey,vercmp,' + \ '_pkgsplit@pkgsplit,_pkg_str,_unknown_repo', 'subprocess', @@ -1800,7 +1801,8 @@ class dblink(object): if self._scheduler is None: # We create a scheduler instance and use it to # log unmerge output separately from merge output. - self._scheduler = SchedulerInterface(EventLoop(main=False)) + self._scheduler = SchedulerInterface(portage._internal_caller and + global_event_loop() or EventLoop(main=False)) if self.settings.get("PORTAGE_BACKGROUND") == "subprocess": if self.settings.get("PORTAGE_BACKGROUND_UNMERGE") == "1": self.settings["PORTAGE_BACKGROUND"] = "1" @@ -4742,7 +4744,8 @@ class dblink(object): proc = SyncfsProcess(paths=paths, scheduler=(self._scheduler or - SchedulerInterface(EventLoop(main=False)))) + SchedulerInterface(portage._internal_caller and + global_event_loop() or EventLoop(main=False)))) proc.start() returncode = proc.wait() @@ -4766,7 +4769,8 @@ class dblink(object): self.lockdb() self.vartree.dbapi._bump_mtime(self.mycpv) if self._scheduler is None: - self._scheduler = SchedulerInterface(EventLoop(main=False)) + self._scheduler = SchedulerInterface(portage._internal_caller and + global_event_loop() or EventLoop(main=False)) try: retval = self.treewalk(mergeroot, myroot, inforoot, myebuild, cleanup=cleanup, mydbapi=mydbapi, prev_mtimes=prev_mtimes, @@ -4950,7 +4954,8 @@ def merge(mycat, mypkg, pkgloc, infloc, merge_task = MergeProcess( mycat=mycat, mypkg=mypkg, settings=settings, treetype=mytree, vartree=vartree, - scheduler=(scheduler or EventLoop(main=False)), + scheduler=(scheduler or portage._internal_caller and + global_event_loop() or EventLoop(main=False)), background=background, blockers=blockers, pkgloc=pkgloc, infloc=infloc, myebuild=myebuild, mydbapi=mydbapi, prev_mtimes=prev_mtimes, logfile=settings.get('PORTAGE_LOG_FILE')) diff --git a/pym/portage/package/ebuild/_spawn_nofetch.py b/pym/portage/package/ebuild/_spawn_nofetch.py index 151fc2ee4..898eb03a1 100644 --- a/pym/portage/package/ebuild/_spawn_nofetch.py +++ b/pym/portage/package/ebuild/_spawn_nofetch.py @@ -1,4 +1,4 @@ -# Copyright 2010-2012 Gentoo Foundation +# Copyright 2010-2013 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 import tempfile @@ -12,6 +12,7 @@ from portage.package.ebuild.doebuild import doebuild_environment from portage.package.ebuild.prepare_build_dirs import prepare_build_dirs from portage.util._async.SchedulerInterface import SchedulerInterface from portage.util._eventloop.EventLoop import EventLoop +from portage.util._eventloop.global_event_loop import global_event_loop from _emerge.EbuildPhase import EbuildPhase def spawn_nofetch(portdb, ebuild_path, settings=None): @@ -79,7 +80,8 @@ def spawn_nofetch(portdb, ebuild_path, settings=None): prepare_build_dirs(settings=settings) ebuild_phase = EbuildPhase(background=False, phase='nofetch', - scheduler=SchedulerInterface(EventLoop(main=False)), + scheduler=SchedulerInterface(portage._internal_caller and + global_event_loop() or EventLoop(main=False)), settings=settings) ebuild_phase.start() ebuild_phase.wait() diff --git a/pym/portage/package/ebuild/doebuild.py b/pym/portage/package/ebuild/doebuild.py index ff7776cce..646faf44b 100644 --- a/pym/portage/package/ebuild/doebuild.py +++ b/pym/portage/package/ebuild/doebuild.py @@ -33,6 +33,7 @@ portage.proxy.lazyimport.lazyimport(globals(), 'portage.util._desktop_entry:validate_desktop_entry', 'portage.util._async.SchedulerInterface:SchedulerInterface', 'portage.util._eventloop.EventLoop:EventLoop', + 'portage.util._eventloop.global_event_loop:global_event_loop', 'portage.util.ExtractKernelVersion:ExtractKernelVersion' ) @@ -141,7 +142,8 @@ def _spawn_phase(phase, settings, actionmap=None, **kwargs): return _doebuild_spawn(phase, settings, actionmap=actionmap, **kwargs) ebuild_phase = EbuildPhase(actionmap=actionmap, background=False, - phase=phase, scheduler=SchedulerInterface(EventLoop(main=False)), + phase=phase, scheduler=SchedulerInterface(portage._internal_caller and + global_event_loop() or EventLoop(main=False)), settings=settings) ebuild_phase.start() ebuild_phase.wait() @@ -699,7 +701,8 @@ def doebuild(myebuild, mydo, _unused=None, settings=None, debug=0, listonly=0, if not returnpid and \ 'PORTAGE_BUILDDIR_LOCKED' not in mysettings: builddir_lock = EbuildBuildDir( - scheduler=EventLoop(main=False), + scheduler=(portage._internal_caller and + global_event_loop() or EventLoop(main=False)), settings=mysettings) builddir_lock.lock() try: @@ -841,7 +844,8 @@ def doebuild(myebuild, mydo, _unused=None, settings=None, debug=0, listonly=0, if builddir_lock is None and \ 'PORTAGE_BUILDDIR_LOCKED' not in mysettings: builddir_lock = EbuildBuildDir( - scheduler=EventLoop(main=False), + scheduler=(portage._internal_caller and + global_event_loop() or EventLoop(main=False)), settings=mysettings) builddir_lock.lock() try: @@ -864,7 +868,8 @@ def doebuild(myebuild, mydo, _unused=None, settings=None, debug=0, listonly=0, if not returnpid and \ 'PORTAGE_BUILDDIR_LOCKED' not in mysettings: builddir_lock = EbuildBuildDir( - scheduler=EventLoop(main=False), + scheduler=(portage._internal_caller and + global_event_loop() or EventLoop(main=False)), settings=mysettings) builddir_lock.lock() mystatus = prepare_build_dirs(myroot, mysettings, cleanup) @@ -1204,7 +1209,9 @@ def _prepare_env_file(settings): """ env_extractor = BinpkgEnvExtractor(background=False, - scheduler=EventLoop(main=False), settings=settings) + scheduler=(portage._internal_caller and + global_event_loop() or EventLoop(main=False)), + settings=settings) if env_extractor.dest_env_exists(): # There are lots of possible states when doebuild() @@ -1476,7 +1483,8 @@ def spawn(mystring, mysettings, debug=0, free=0, droppriv=0, sesandbox=0, fakero proc = EbuildSpawnProcess( background=False, args=mystring, - scheduler=SchedulerInterface(EventLoop(main=False)), + scheduler=SchedulerInterface(portage._internal_caller and + global_event_loop() or EventLoop(main=False)), spawn_func=spawn_func, settings=mysettings, **keywords) -- 2.26.2