PollScheduler: remove register/unregister methods
authorZac Medico <zmedico@gentoo.org>
Sat, 6 Oct 2012 04:31:56 +0000 (21:31 -0700)
committerZac Medico <zmedico@gentoo.org>
Sat, 6 Oct 2012 04:31:56 +0000 (21:31 -0700)
These methods were aliases for the EventLoop io_add_watch and
source_remove methods. Migrating to the EventLoop method names allows
an EventLoop instance to substitute for a PollScheduler inside
subclasses of AbstractPollTask.

pym/_emerge/AbstractPollTask.py
pym/_emerge/AsynchronousLock.py
pym/_emerge/EbuildMetadataPhase.py
pym/_emerge/FifoIpcDaemon.py
pym/_emerge/PipeReader.py
pym/_emerge/PollScheduler.py
pym/_emerge/SpawnProcess.py
pym/_emerge/SubProcess.py
pym/portage/dbapi/_MergeProcess.py
pym/portage/tests/ebuild/test_ipc_daemon.py

index 2c847092525e06cde96e0840b97ca9126dd432a0..3f6dd6cef0e95b7a92003af6513883de142b4682 100644 (file)
@@ -151,4 +151,4 @@ class AbstractPollTask(AsynchronousTask):
                        while self._registered and not timeout_cb.timed_out:
                                self.scheduler.iteration()
                finally:
-                       self.scheduler.unregister(timeout_cb.timeout_id)
+                       self.scheduler.source_remove(timeout_cb.timeout_id)
index 587aa4650ea8ceb8f6165468ae3d810d0427553b..6e2d9bd28eedb54ad973a76949b9b0e9e78ecf09 100644 (file)
@@ -116,7 +116,7 @@ class _LockThread(AbstractPollTask):
                for f in self._files.values():
                        fcntl.fcntl(f, fcntl.F_SETFL,
                                fcntl.fcntl(f, fcntl.F_GETFL) | os.O_NONBLOCK)
-               self._reg_id = self.scheduler.register(self._files['pipe_read'],
+               self._reg_id = self.scheduler.io_add_watch(self._files['pipe_read'],
                        self.scheduler.IO_IN, self._output_handler)
                self._registered = True
                threading_mod = threading
@@ -164,7 +164,7 @@ class _LockThread(AbstractPollTask):
                        self._thread = None
 
                if self._reg_id is not None:
-                       self.scheduler.unregister(self._reg_id)
+                       self.scheduler.source_remove(self._reg_id)
                        self._reg_id = None
 
                if self._files is not None:
@@ -192,7 +192,7 @@ class _LockProcess(AbstractPollTask):
                self._files['pipe_out'] = out_pw
                fcntl.fcntl(in_pr, fcntl.F_SETFL,
                        fcntl.fcntl(in_pr, fcntl.F_GETFL) | os.O_NONBLOCK)
-               self._reg_id = self.scheduler.register(in_pr,
+               self._reg_id = self.scheduler.io_add_watch(in_pr,
                        self.scheduler.IO_IN, self._output_handler)
                self._registered = True
                self._proc = SpawnProcess(
@@ -273,7 +273,7 @@ class _LockProcess(AbstractPollTask):
                self._registered = False
 
                if self._reg_id is not None:
-                       self.scheduler.unregister(self._reg_id)
+                       self.scheduler.source_remove(self._reg_id)
                        self._reg_id = None
 
                if self._files is not None:
index 1ffa1bb238a92b39ccaa071e09406c9484157736..a6c515a4cc7f1a555a4fc96b59e5b74bcfc86083 100644 (file)
@@ -96,7 +96,7 @@ class EbuildMetadataPhase(SubProcess):
 
                self._raw_metadata = []
                files.ebuild = master_fd
-               self._reg_id = self.scheduler.register(files.ebuild,
+               self._reg_id = self.scheduler.io_add_watch(files.ebuild,
                        self._registered_events, self._output_handler)
                self._registered = True
 
index de9dc67b16442418e124dcf47750815540e8b958..959c0076958b288366b9d1b22b2956334492c530 100644 (file)
@@ -21,7 +21,7 @@ class FifoIpcDaemon(AbstractPollTask):
                self._files.pipe_in = \
                        os.open(self.input_fifo, os.O_RDONLY|os.O_NONBLOCK)
 
-               self._reg_id = self.scheduler.register(
+               self._reg_id = self.scheduler.io_add_watch(
                        self._files.pipe_in,
                        self._registered_events, self._input_handler)
 
@@ -32,11 +32,11 @@ class FifoIpcDaemon(AbstractPollTask):
                Re-open the input stream, in order to suppress
                POLLHUP events (bug #339976).
                """
-               self.scheduler.unregister(self._reg_id)
+               self.scheduler.source_remove(self._reg_id)
                os.close(self._files.pipe_in)
                self._files.pipe_in = \
                        os.open(self.input_fifo, os.O_RDONLY|os.O_NONBLOCK)
-               self._reg_id = self.scheduler.register(
+               self._reg_id = self.scheduler.io_add_watch(
                        self._files.pipe_in,
                        self._registered_events, self._input_handler)
 
@@ -69,7 +69,7 @@ class FifoIpcDaemon(AbstractPollTask):
                self._registered = False
 
                if self._reg_id is not None:
-                       self.scheduler.unregister(self._reg_id)
+                       self.scheduler.source_remove(self._reg_id)
                        self._reg_id = None
 
                if self._files is not None:
index 90febdf4456dd6b3c943a6b94bafdbb9860a05e7..3eb9d36df1a7dca6488399fbb414419d6e4817d2 100644 (file)
@@ -29,7 +29,7 @@ class PipeReader(AbstractPollTask):
                for f in self.input_files.values():
                        fcntl.fcntl(f.fileno(), fcntl.F_SETFL,
                                fcntl.fcntl(f.fileno(), fcntl.F_GETFL) | os.O_NONBLOCK)
-                       self._reg_ids.add(self.scheduler.register(f.fileno(),
+                       self._reg_ids.add(self.scheduler.io_add_watch(f.fileno(),
                                self._registered_events, output_handler))
                self._registered = True
 
@@ -102,7 +102,7 @@ class PipeReader(AbstractPollTask):
 
                if self._reg_ids is not None:
                        for reg_id in self._reg_ids:
-                               self.scheduler.unregister(reg_id)
+                               self.scheduler.source_remove(reg_id)
                        self._reg_ids = None
 
                if self.input_files is not None:
index 1185cd726a2e78ecffb966ab16f81cbce7e9da54..dbf137f85a4d3c8b2f7114b404901a3a7b9b4531 100644 (file)
@@ -27,8 +27,8 @@ class PollScheduler(object):
                __slots__ = ("IO_ERR", "IO_HUP", "IO_IN", "IO_NVAL", "IO_OUT",
                        "IO_PRI", "child_watch_add",
                        "idle_add", "io_add_watch", "iteration",
-                       "output", "register", "run",
-                       "source_remove", "timeout_add", "unregister")
+                       "output", "run",
+                       "source_remove", "timeout_add")
 
        def __init__(self, main=False, event_loop=None):
                """
@@ -61,10 +61,8 @@ class PollScheduler(object):
                        io_add_watch=self._event_loop.io_add_watch,
                        iteration=self._event_loop.iteration,
                        output=self._task_output,
-                       register=self._event_loop.io_add_watch,
                        source_remove=self._event_loop.source_remove,
-                       timeout_add=self._event_loop.timeout_add,
-                       unregister=self._event_loop.source_remove)
+                       timeout_add=self._event_loop.timeout_add)
 
        def terminate(self):
                """
index c7863c1ec6dc33ca1cc6bf0e13576ae2d2d8caf3..ab152c3c37a6c7960f62e276df6080ab13ce90d4 100644 (file)
@@ -116,7 +116,7 @@ class SpawnProcess(SubProcess):
                kwargs["returnpid"] = True
                kwargs.pop("logfile", None)
 
-               self._reg_id = self.scheduler.register(files.process,
+               self._reg_id = self.scheduler.io_add_watch(files.process,
                        self._registered_events, output_handler)
                self._registered = True
 
index 76b313fc2f6b55ac84ca926bb7dbe1baa623976c..92cbc27ab4f3b3abec5cc7a8cac5bb0b294da6c5 100644 (file)
@@ -116,7 +116,7 @@ class SubProcess(AbstractPollTask):
                self._registered = False
 
                if self._reg_id is not None:
-                       self.scheduler.unregister(self._reg_id)
+                       self.scheduler.source_remove(self._reg_id)
                        self._reg_id = None
 
                if self._files is not None:
index a9cc2b32fb05eb446939a387eb418e01731a1559..469ba0b3af73f445cd1e3f141f25840cfb2d38c2 100644 (file)
@@ -90,7 +90,7 @@ class MergeProcess(ForkProcess):
                                        reporter(msg, phase=phase, key=key, out=out)
 
                if event & self.scheduler.IO_HUP:
-                       self.scheduler.unregister(self._elog_reg_id)
+                       self.scheduler.source_remove(self._elog_reg_id)
                        self._elog_reg_id = None
                        os.close(self._elog_reader_fd)
                        self._elog_reader_fd = None
@@ -119,7 +119,7 @@ class MergeProcess(ForkProcess):
                        blockers=blockers, scheduler=self.scheduler,
                        pipe=elog_writer_fd)
                fd_pipes[elog_writer_fd] = elog_writer_fd
-               self._elog_reg_id = self.scheduler.register(elog_reader_fd,
+               self._elog_reg_id = self.scheduler.io_add_watch(elog_reader_fd,
                        self._registered_events, self._elog_output_handler)
 
                # If a concurrent emerge process tries to install a package
@@ -231,7 +231,7 @@ class MergeProcess(ForkProcess):
 
                self._unlock_vdb()
                if self._elog_reg_id is not None:
-                       self.scheduler.unregister(self._elog_reg_id)
+                       self.scheduler.source_remove(self._elog_reg_id)
                        self._elog_reg_id = None
                if self._elog_reader_fd is not None:
                        os.close(self._elog_reader_fd)
index d4328a1d6ce06fa51f354a5700a351a83ce5fd75..5f2257cbb4b4b7aabb996860560070a4a119d70e 100644 (file)
@@ -16,7 +16,6 @@ from portage.util import ensure_dirs
 from portage.util._async.ForkProcess import ForkProcess
 from portage.util._async.TaskScheduler import TaskScheduler
 from portage.util._eventloop.global_event_loop import global_event_loop
-from _emerge.PollScheduler import PollScheduler
 from _emerge.SpawnProcess import SpawnProcess
 from _emerge.EbuildBuildDir import EbuildBuildDir
 from _emerge.EbuildIpcDaemon import EbuildIpcDaemon
@@ -58,7 +57,7 @@ class IpcDaemonTestCase(TestCase):
                                        os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"]
 
                        build_dir = EbuildBuildDir(
-                               scheduler=PollScheduler(event_loop=event_loop).sched_iface,
+                               scheduler=event_loop,
                                settings=env)
                        build_dir.lock()
                        ensure_dirs(env['PORTAGE_BUILDDIR'])