當前位置: 首頁>>代碼示例>>Python>>正文


Python asyncio.SafeChildWatcher方法代碼示例

本文整理匯總了Python中asyncio.SafeChildWatcher方法的典型用法代碼示例。如果您正苦於以下問題:Python asyncio.SafeChildWatcher方法的具體用法?Python asyncio.SafeChildWatcher怎麽用?Python asyncio.SafeChildWatcher使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在asyncio的用法示例。


在下文中一共展示了asyncio.SafeChildWatcher方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_get_child_watcher_thread

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import SafeChildWatcher [as 別名]
def test_get_child_watcher_thread(self):

        def f():
            policy.set_event_loop(policy.new_event_loop())

            self.assertIsInstance(policy.get_event_loop(),
                                  asyncio.AbstractEventLoop)
            watcher = policy.get_child_watcher()

            self.assertIsInstance(watcher, asyncio.SafeChildWatcher)
            self.assertIsNone(watcher._loop)

            policy.get_event_loop().close()

        policy = self.create_policy()

        th = threading.Thread(target=f)
        th.start()
        th.join() 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:21,代碼來源:test_unix_events.py

示例2: setup_test_loop

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import SafeChildWatcher [as 別名]
def setup_test_loop(loop_factory=asyncio.new_event_loop):
    """Create and return an asyncio.BaseEventLoop instance.

    The caller should also call teardown_test_loop, once they are done
    with the loop.
    """
    loop = loop_factory()
    asyncio.set_event_loop(loop)
    if sys.platform != "win32":
        policy = asyncio.get_event_loop_policy()
        watcher = asyncio.SafeChildWatcher()
        watcher.attach_loop(loop)
        policy.set_child_watcher(watcher)
    return loop 
開發者ID:Eyepea,項目名稱:aiosip,代碼行數:16,代碼來源:pytest_plugin.py

示例3: test_read_all_from_pipe_reader

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import SafeChildWatcher [as 別名]
def test_read_all_from_pipe_reader(self):
        # See asyncio issue 168.  This test is derived from the example
        # subprocess_attach_read_pipe.py, but we configure the
        # StreamReader's limit so that twice it is less than the size
        # of the data writter.  Also we must explicitly attach a child
        # watcher to the event loop.

        code = """\
import os, sys
fd = int(sys.argv[1])
os.write(fd, b'data')
os.close(fd)
"""
        rfd, wfd = os.pipe()
        args = [sys.executable, '-c', code, str(wfd)]

        pipe = open(rfd, 'rb', 0)
        reader = asyncio.StreamReader(loop=self.loop, limit=1)
        protocol = asyncio.StreamReaderProtocol(reader, loop=self.loop)
        transport, _ = self.loop.run_until_complete(
            self.loop.connect_read_pipe(lambda: protocol, pipe))

        watcher = asyncio.SafeChildWatcher()
        watcher.attach_loop(self.loop)
        try:
            asyncio.set_child_watcher(watcher)
            create = asyncio.create_subprocess_exec(*args,
                                                    pass_fds={wfd},
                                                    loop=self.loop)
            proc = self.loop.run_until_complete(create)
            self.loop.run_until_complete(proc.wait())
        finally:
            asyncio.set_child_watcher(None)

        os.close(wfd)
        data = self.loop.run_until_complete(reader.read(-1))
        self.assertEqual(data, b'data') 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:39,代碼來源:test_streams.py

示例4: setUp

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import SafeChildWatcher [as 別名]
def setUp(self):
            super().setUp()
            watcher = asyncio.SafeChildWatcher()
            watcher.attach_loop(self.loop)
            asyncio.set_child_watcher(watcher) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:7,代碼來源:test_events.py

示例5: waitpid

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import SafeChildWatcher [as 別名]
def waitpid(self, pid, flags):
        if isinstance(self.watcher, asyncio.SafeChildWatcher) or pid != -1:
            self.assertGreater(pid, 0)
        try:
            if pid < 0:
                return self.zombies.popitem()
            else:
                return pid, self.zombies.pop(pid)
        except KeyError:
            pass
        if self.running:
            return 0, 0
        else:
            raise ChildProcessError() 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:16,代碼來源:test_unix_events.py

示例6: create_watcher

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import SafeChildWatcher [as 別名]
def create_watcher(self):
        return asyncio.SafeChildWatcher() 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:4,代碼來源:test_unix_events.py

示例7: test_get_child_watcher

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import SafeChildWatcher [as 別名]
def test_get_child_watcher(self):
        policy = self.create_policy()
        self.assertIsNone(policy._watcher)

        watcher = policy.get_child_watcher()
        self.assertIsInstance(watcher, asyncio.SafeChildWatcher)

        self.assertIs(policy._watcher, watcher)

        self.assertIs(watcher, policy.get_child_watcher())
        self.assertIsNone(watcher._loop) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:13,代碼來源:test_unix_events.py

示例8: install

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import SafeChildWatcher [as 別名]
def install(gtk=False):
    """Set the default event loop policy.

    Call this as early as possible to ensure everything has a reference to the
    correct event loop.

    Set ``gtk`` to True if you intend to use Gtk in your application.

    If ``gtk`` is True and Gtk is not available, will raise `ValueError`.

    Note that this class performs some monkey patching of asyncio to ensure
    correct functionality.
    """

    if gtk:
        from .gtk import GtkEventLoopPolicy
        policy = GtkEventLoopPolicy()
    else:
        from .glib_events import GLibEventLoopPolicy
        policy = GLibEventLoopPolicy()

    # There are some libraries that use SafeChildWatcher directly (which is
    # completely reasonable), so we have to ensure that it is our version. I'm
    # sorry, I know this isn't great but it's basically the best that we have.
    from .glib_events import GLibChildWatcher
    asyncio.SafeChildWatcher = GLibChildWatcher
    asyncio.set_event_loop_policy(policy) 
開發者ID:pychess,項目名稱:pychess,代碼行數:29,代碼來源:utils.py

示例9: _check_unix

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import SafeChildWatcher [as 別名]
def _check_unix(self):
        if not hasattr(asyncio, "SafeChildWatcher"):
            raise NotImplementedError 
開發者ID:Martiusweb,項目名稱:asynctest,代碼行數:5,代碼來源:case.py

示例10: get_child_watcher

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import SafeChildWatcher [as 別名]
def get_child_watcher(self):
        self._check_unix()
        if self.loop:
            if self.watcher is None:
                self.watcher = asyncio.SafeChildWatcher()
                self.watcher.attach_loop(self.loop)

            return self.watcher
        else:
            return self.original_policy.get_child_watcher() 
開發者ID:Martiusweb,項目名稱:asynctest,代碼行數:12,代碼來源:case.py

示例11: test_read_all_from_pipe_reader

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import SafeChildWatcher [as 別名]
def test_read_all_from_pipe_reader(self):
        # See Tulip issue 168.  This test is derived from the example
        # subprocess_attach_read_pipe.py, but we configure the
        # StreamReader's limit so that twice it is less than the size
        # of the data writter.  Also we must explicitly attach a child
        # watcher to the event loop.

        code = """\
import os, sys
fd = int(sys.argv[1])
os.write(fd, b'data')
os.close(fd)
"""
        rfd, wfd = os.pipe()
        args = [sys.executable, '-c', code, str(wfd)]

        pipe = open(rfd, 'rb', 0)
        reader = asyncio.StreamReader(loop=self.loop, limit=1)
        protocol = asyncio.StreamReaderProtocol(reader, loop=self.loop)
        transport, _ = self.loop.run_until_complete(
            self.loop.connect_read_pipe(lambda: protocol, pipe))

        watcher = asyncio.SafeChildWatcher()
        watcher.attach_loop(self.loop)
        try:
            asyncio.set_child_watcher(watcher)
            create = asyncio.create_subprocess_exec(*args,
                                                    pass_fds={wfd},
                                                    loop=self.loop)
            proc = self.loop.run_until_complete(create)
            self.loop.run_until_complete(proc.wait())
        finally:
            asyncio.set_child_watcher(None)

        os.close(wfd)
        data = self.loop.run_until_complete(reader.read(-1))
        self.assertEqual(data, b'data') 
開發者ID:hhstore,項目名稱:annotated-py-projects,代碼行數:39,代碼來源:test_streams.py


注:本文中的asyncio.SafeChildWatcher方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。