Substitute EventLoop for PollScheduler.
authorZac Medico <zmedico@gentoo.org>
Sat, 6 Oct 2012 05:20:07 +0000 (22:20 -0700)
committerZac Medico <zmedico@gentoo.org>
Sat, 6 Oct 2012 05:20:07 +0000 (22:20 -0700)
EventLoop suffices for all of these cases. EventLoop(main=False) is
used for thread safety where API consumers may be using threads.

pym/portage/dbapi/_MergeProcess.py
pym/portage/dbapi/porttree.py
pym/portage/dbapi/vartree.py
pym/portage/package/ebuild/doebuild.py
pym/portage/tests/ebuild/test_spawn.py
pym/portage/tests/lazyimport/test_lazy_import_portage_baseline.py
pym/portage/tests/locks/test_asynchronous_lock.py

index 469ba0b3af73f445cd1e3f141f25840cfb2d38c2..bb607d37fe83992febb8bbcf687d53aa75276f70 100644 (file)
@@ -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
 
index b1a81b271cea1a1ab3525c6a8958c851e66e9078..dba0ef53d2044d67363dac978288fa551ad34d40 100644 (file)
@@ -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()
index 5299b298fd78da0042a794adb33eec4cbeab33d3..f00a87ad2adfe6648c17f217c40958e9dd72ae1f 100644 (file)
@@ -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'))
index 9deed98d79fa3f68b7bcf6b87828a9a76c2d0b08..39cd22824cf4d1e0d1b37e201f5407520df8840d 100644 (file)
@@ -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()
index fea4738d415c2170d1ca8840877373f9d4ae9da5..3a07b150a9555ec09403f17f954e6745f7bf753b 100644 (file)
@@ -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)
index c7ebbaff9214a95fc15e2605e01ddf6be6c7e42a..080cf3f982a8400666ad3688ee5102c79b3bcb9d 100644 (file)
@@ -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')
index 49dd10ec40caeb3e294da53d5305f1a7c0f2f4e8..3a2ccfb84a21d92c1c454ecd4b5f4789a9d091b7 100644 (file)
@@ -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')