From: Zac Medico Date: Sat, 6 Oct 2012 05:20:07 +0000 (-0700) Subject: Substitute EventLoop for PollScheduler. X-Git-Tag: v2.2.0_alpha136~23 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=e9ea4bc74f16e6c120fdf9c1926dfcb7de7bd135;p=portage.git Substitute EventLoop for PollScheduler. EventLoop suffices for all of these cases. EventLoop(main=False) is used for thread safety where API consumers may be using threads. --- diff --git a/pym/portage/dbapi/_MergeProcess.py b/pym/portage/dbapi/_MergeProcess.py index 469ba0b3a..bb607d37f 100644 --- a/pym/portage/dbapi/_MergeProcess.py +++ b/pym/portage/dbapi/_MergeProcess.py @@ -116,8 +116,7 @@ class MergeProcess(ForkProcess): blockers = self.blockers() mylink = portage.dblink(self.mycat, self.mypkg, settings=self.settings, treetype=self.treetype, vartree=self.vartree, - blockers=blockers, scheduler=self.scheduler, - pipe=elog_writer_fd) + blockers=blockers, pipe=elog_writer_fd) fd_pipes[elog_writer_fd] = elog_writer_fd self._elog_reg_id = self.scheduler.io_add_watch(elog_reader_fd, self._registered_events, self._elog_output_handler) @@ -166,11 +165,6 @@ class MergeProcess(ForkProcess): portage.output.havecolor = self.settings.get('NOCOLOR') \ not in ('yes', 'true') - # In this subprocess we want mylink._display_merge() to use - # stdout/stderr directly since they are pipes. This behavior - # is triggered when mylink._scheduler is None. - mylink._scheduler = None - # Avoid wastful updates of the vdb cache. self.vartree.dbapi._flush_cache_enabled = False diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py index b1a81b271..dba0ef53d 100644 --- a/pym/portage/dbapi/porttree.py +++ b/pym/portage/dbapi/porttree.py @@ -33,8 +33,8 @@ from portage import os from portage import _encodings from portage import _unicode_encode from portage import OrderedDict +from portage.util._eventloop.EventLoop import EventLoop from _emerge.EbuildMetadataPhase import EbuildMetadataPhase -from _emerge.PollScheduler import PollScheduler import os as _os import sys @@ -96,7 +96,7 @@ 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._scheduler = PollScheduler().sched_iface + self._event_loop = EventLoop(main=False) self.depcachedir = os.path.realpath(self.settings.depcachedir) if os.environ.get("SANDBOX_ON") == "1": @@ -448,7 +448,7 @@ class portdbapi(dbapi): proc = EbuildMetadataPhase(cpv=mycpv, ebuild_hash=ebuild_hash, portdb=self, - repo_path=mylocation, scheduler=self._scheduler, + repo_path=mylocation, scheduler=self._event_loop, settings=self.doebuild_settings) proc.start() diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index 5299b298f..f00a87ad2 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -32,6 +32,7 @@ portage.proxy.lazyimport.lazyimport(globals(), 'portage.util.movefile:movefile', 'portage.util._dyn_libs.PreservedLibsRegistry:PreservedLibsRegistry', 'portage.util._dyn_libs.LinkageMapELF:LinkageMapELF@LinkageMap', + 'portage.util._eventloop.EventLoop:EventLoop', 'portage.versions:best,catpkgsplit,catsplit,cpv_getkey,vercmp,' + \ '_pkgsplit@pkgsplit,_pkg_str', 'subprocess', @@ -4814,7 +4815,7 @@ def merge(mycat, mypkg, pkgloc, infloc, merge_task = MergeProcess( mycat=mycat, mypkg=mypkg, settings=settings, treetype=mytree, vartree=vartree, - scheduler=(scheduler or PollScheduler().sched_iface), + scheduler=(scheduler 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/doebuild.py b/pym/portage/package/ebuild/doebuild.py index 9deed98d7..39cd22824 100644 --- a/pym/portage/package/ebuild/doebuild.py +++ b/pym/portage/package/ebuild/doebuild.py @@ -29,6 +29,7 @@ portage.proxy.lazyimport.lazyimport(globals(), 'portage.dep._slot_operator:evaluate_slot_operator_equal_deps', 'portage.package.ebuild._spawn_nofetch:spawn_nofetch', 'portage.util._desktop_entry:validate_desktop_entry', + 'portage.util._eventloop.EventLoop:EventLoop', 'portage.util.ExtractKernelVersion:ExtractKernelVersion' ) @@ -691,7 +692,7 @@ def doebuild(myebuild, mydo, _unused=None, settings=None, debug=0, listonly=0, if not returnpid and \ 'PORTAGE_BUILDIR_LOCKED' not in mysettings: builddir_lock = EbuildBuildDir( - scheduler=PollScheduler().sched_iface, + scheduler=EventLoop(main=False), settings=mysettings) builddir_lock.lock() try: @@ -833,7 +834,7 @@ def doebuild(myebuild, mydo, _unused=None, settings=None, debug=0, listonly=0, if builddir_lock is None and \ 'PORTAGE_BUILDIR_LOCKED' not in mysettings: builddir_lock = EbuildBuildDir( - scheduler=PollScheduler().sched_iface, + scheduler=EventLoop(main=False), settings=mysettings) builddir_lock.lock() try: @@ -856,7 +857,7 @@ def doebuild(myebuild, mydo, _unused=None, settings=None, debug=0, listonly=0, if not returnpid and \ 'PORTAGE_BUILDIR_LOCKED' not in mysettings: builddir_lock = EbuildBuildDir( - scheduler=PollScheduler().sched_iface, + scheduler=EventLoop(main=False), settings=mysettings) builddir_lock.lock() mystatus = prepare_build_dirs(myroot, mysettings, cleanup) @@ -1197,7 +1198,7 @@ def _prepare_env_file(settings): """ env_extractor = BinpkgEnvExtractor(background=False, - scheduler=PollScheduler().sched_iface, settings=settings) + scheduler=EventLoop(main=False), settings=settings) if env_extractor.dest_env_exists(): # There are lots of possible states when doebuild() diff --git a/pym/portage/tests/ebuild/test_spawn.py b/pym/portage/tests/ebuild/test_spawn.py index fea4738d4..3a07b150a 100644 --- a/pym/portage/tests/ebuild/test_spawn.py +++ b/pym/portage/tests/ebuild/test_spawn.py @@ -10,8 +10,8 @@ from portage import _encodings from portage import _unicode_encode from portage.const import BASH_BINARY from portage.tests import TestCase +from portage.util._eventloop.global_event_loop import global_event_loop from _emerge.SpawnProcess import SpawnProcess -from _emerge.PollScheduler import PollScheduler class SpawnTestCase(TestCase): @@ -22,12 +22,11 @@ class SpawnTestCase(TestCase): os.close(fd) null_fd = os.open('/dev/null', os.O_RDWR) test_string = 2 * "blah blah blah\n" - scheduler = PollScheduler().sched_iface proc = SpawnProcess( args=[BASH_BINARY, "-c", "echo -n '%s'" % test_string], env={}, fd_pipes={0:sys.stdin.fileno(), 1:null_fd, 2:null_fd}, - scheduler=scheduler, + scheduler=global_event_loop(), logfile=logfile) proc.start() os.close(null_fd) diff --git a/pym/portage/tests/lazyimport/test_lazy_import_portage_baseline.py b/pym/portage/tests/lazyimport/test_lazy_import_portage_baseline.py index c7ebbaff9..080cf3f98 100644 --- a/pym/portage/tests/lazyimport/test_lazy_import_portage_baseline.py +++ b/pym/portage/tests/lazyimport/test_lazy_import_portage_baseline.py @@ -6,8 +6,8 @@ import portage from portage import os from portage.const import PORTAGE_PYM_PATH from portage.tests import TestCase +from portage.util._eventloop.global_event_loop import global_event_loop -from _emerge.PollScheduler import PollScheduler from _emerge.PipeReader import PipeReader from _emerge.SpawnProcess import SpawnProcess @@ -52,7 +52,7 @@ sys.stdout.write(" ".join(k for k in sys.modules # then the above PYTHONPATH override doesn't help. env['PORTAGE_PYM_PATH'] = PORTAGE_PYM_PATH - scheduler = PollScheduler().sched_iface + scheduler = global_event_loop() master_fd, slave_fd = os.pipe() master_file = os.fdopen(master_fd, 'rb', 0) slave_file = os.fdopen(slave_fd, 'wb') diff --git a/pym/portage/tests/locks/test_asynchronous_lock.py b/pym/portage/tests/locks/test_asynchronous_lock.py index 49dd10ec4..3a2ccfb84 100644 --- a/pym/portage/tests/locks/test_asynchronous_lock.py +++ b/pym/portage/tests/locks/test_asynchronous_lock.py @@ -7,13 +7,13 @@ import tempfile from portage import os from portage import shutil from portage.tests import TestCase +from portage.util._eventloop.global_event_loop import global_event_loop from _emerge.AsynchronousLock import AsynchronousLock -from _emerge.PollScheduler import PollScheduler class AsynchronousLockTestCase(TestCase): def _testAsynchronousLock(self): - scheduler = PollScheduler().sched_iface + scheduler = global_event_loop() tempdir = tempfile.mkdtemp() try: path = os.path.join(tempdir, 'lock_me') @@ -53,7 +53,7 @@ class AsynchronousLockTestCase(TestCase): os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"] = prev_state def _testAsynchronousLockWait(self): - scheduler = PollScheduler().sched_iface + scheduler = global_event_loop() tempdir = tempfile.mkdtemp() try: path = os.path.join(tempdir, 'lock_me') @@ -94,7 +94,7 @@ class AsynchronousLockTestCase(TestCase): os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"] = prev_state def _testAsynchronousLockWaitCancel(self): - scheduler = PollScheduler().sched_iface + scheduler = global_event_loop() tempdir = tempfile.mkdtemp() try: path = os.path.join(tempdir, 'lock_me') @@ -132,7 +132,7 @@ class AsynchronousLockTestCase(TestCase): os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"] = prev_state def _testAsynchronousLockWaitKill(self): - scheduler = PollScheduler().sched_iface + scheduler = global_event_loop() tempdir = tempfile.mkdtemp() try: path = os.path.join(tempdir, 'lock_me')