From 14230dd467c4f0136cb99e83f2d610de166b772b Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Fri, 5 Oct 2012 21:31:56 -0700 Subject: [PATCH] PollScheduler: remove register/unregister methods 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 | 2 +- pym/_emerge/AsynchronousLock.py | 8 ++++---- pym/_emerge/EbuildMetadataPhase.py | 2 +- pym/_emerge/FifoIpcDaemon.py | 8 ++++---- pym/_emerge/PipeReader.py | 4 ++-- pym/_emerge/PollScheduler.py | 8 +++----- pym/_emerge/SpawnProcess.py | 2 +- pym/_emerge/SubProcess.py | 2 +- pym/portage/dbapi/_MergeProcess.py | 6 +++--- pym/portage/tests/ebuild/test_ipc_daemon.py | 3 +-- 10 files changed, 21 insertions(+), 24 deletions(-) diff --git a/pym/_emerge/AbstractPollTask.py b/pym/_emerge/AbstractPollTask.py index 2c8470925..3f6dd6cef 100644 --- a/pym/_emerge/AbstractPollTask.py +++ b/pym/_emerge/AbstractPollTask.py @@ -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) diff --git a/pym/_emerge/AsynchronousLock.py b/pym/_emerge/AsynchronousLock.py index 587aa4650..6e2d9bd28 100644 --- a/pym/_emerge/AsynchronousLock.py +++ b/pym/_emerge/AsynchronousLock.py @@ -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: diff --git a/pym/_emerge/EbuildMetadataPhase.py b/pym/_emerge/EbuildMetadataPhase.py index 1ffa1bb23..a6c515a4c 100644 --- a/pym/_emerge/EbuildMetadataPhase.py +++ b/pym/_emerge/EbuildMetadataPhase.py @@ -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 diff --git a/pym/_emerge/FifoIpcDaemon.py b/pym/_emerge/FifoIpcDaemon.py index de9dc67b1..959c00769 100644 --- a/pym/_emerge/FifoIpcDaemon.py +++ b/pym/_emerge/FifoIpcDaemon.py @@ -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: diff --git a/pym/_emerge/PipeReader.py b/pym/_emerge/PipeReader.py index 90febdf44..3eb9d36df 100644 --- a/pym/_emerge/PipeReader.py +++ b/pym/_emerge/PipeReader.py @@ -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: diff --git a/pym/_emerge/PollScheduler.py b/pym/_emerge/PollScheduler.py index 1185cd726..dbf137f85 100644 --- a/pym/_emerge/PollScheduler.py +++ b/pym/_emerge/PollScheduler.py @@ -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): """ diff --git a/pym/_emerge/SpawnProcess.py b/pym/_emerge/SpawnProcess.py index c7863c1ec..ab152c3c3 100644 --- a/pym/_emerge/SpawnProcess.py +++ b/pym/_emerge/SpawnProcess.py @@ -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 diff --git a/pym/_emerge/SubProcess.py b/pym/_emerge/SubProcess.py index 76b313fc2..92cbc27ab 100644 --- a/pym/_emerge/SubProcess.py +++ b/pym/_emerge/SubProcess.py @@ -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: diff --git a/pym/portage/dbapi/_MergeProcess.py b/pym/portage/dbapi/_MergeProcess.py index a9cc2b32f..469ba0b3a 100644 --- a/pym/portage/dbapi/_MergeProcess.py +++ b/pym/portage/dbapi/_MergeProcess.py @@ -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) diff --git a/pym/portage/tests/ebuild/test_ipc_daemon.py b/pym/portage/tests/ebuild/test_ipc_daemon.py index d4328a1d6..5f2257cbb 100644 --- a/pym/portage/tests/ebuild/test_ipc_daemon.py +++ b/pym/portage/tests/ebuild/test_ipc_daemon.py @@ -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']) -- 2.26.2