-# Copyright 1998-2011 Gentoo Foundation
+# Copyright 1998-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
+import subprocess
+
from portage import os
from portage.tests import TestCase
from portage.util._pty import _create_pty_or_pipe
-from portage.util._async.TaskScheduler import TaskScheduler
+from portage.util._async.PopenProcess import PopenProcess
+from portage.util._eventloop.global_event_loop import global_event_loop
from _emerge.PipeReader import PipeReader
-from _emerge.SpawnProcess import SpawnProcess
class PipeReaderTestCase(TestCase):
# WARNING: It is very important to use unbuffered mode here,
# in order to avoid issue 5380 with python3.
master_file = os.fdopen(master_fd, 'rb', 0)
- slave_file = os.fdopen(slave_fd, 'wb', 0)
- producer = SpawnProcess(
- args=["bash", "-c", self._echo_cmd % test_string],
- env=os.environ, fd_pipes={1:slave_fd})
+ scheduler = global_event_loop()
consumer = PipeReader(
input_files={"producer" : master_file},
- _use_array=self._use_array)
-
- task_scheduler = TaskScheduler(iter([producer, consumer]), max_jobs=2)
-
- # This will ensure that both tasks have exited, which
- # is necessary to avoid "ResourceWarning: unclosed file"
- # warnings since Python 3.2 (and also ensures that we
- # don't leave any zombie child processes).
- task_scheduler.start()
- slave_file.close()
- task_scheduler.wait()
+ _use_array=self._use_array,
+ scheduler=scheduler)
+
+ producer = PopenProcess(
+ pipe_reader=consumer,
+ proc=subprocess.Popen(["bash", "-c", self._echo_cmd % test_string],
+ stdout=slave_fd),
+ scheduler=scheduler)
+
+ producer.start()
+ os.close(slave_fd)
+ producer.wait()
self.assertEqual(producer.returncode, os.EX_OK)
self.assertEqual(consumer.returncode, os.EX_OK)