示例#1
0
    async def KEAlive(self, finishedState):
        while finishedState.is_set():
            QCoreApplication.processEvents()
            trio.sleep(0.1)
        return

        return
示例#2
0
    async def show_progress(self):
        while self.process is None:
            trio.sleep(0.001)

        logger.info(
            log_helper.generate(
                message=self._get_executable(),
                task_id=self._identifier,
                pid=self.process.pid,
                tags=["command", "execution"],
                status="STARTED",
            ))

        while self.process.poll() is None:
            await self.flush_streams()
        await self.flush_streams(final=True)

        successful = self.process.returncode == 0

        logger.info(
            log_helper.generate(
                message=self._get_executable(),
                task_id=self.identifier,
                pid=self.process.pid,
                returncode=self.process.returncode,
                status="SUCCESS" if successful else "FAILURE",
            ))
示例#3
0
async def corosleep_log3_call(time, callback):
    coro1 = trio.sleep(time)
    coro2 = trio.sleep(time)
    log.info('coros were created!')
    log.debug('waiting for %s seconds' % time)
    await coro1
    log.debug('waiting for %s seconds' % time)
    await coro2
    log.debug('calling callback')
    res = callback(20)
    return res
示例#4
0
async def test_checkpoints():
    async def nothing():
        pass

    with trio.testing.assert_checkpoints():
        await ensure_portal()
    with trio.testing.assert_checkpoints():
        await_(trio.sleep(0))
    with trio.testing.assert_checkpoints():
        await_(trio.sleep(0))
    with trio.testing.assert_no_checkpoints():
        await_(nothing())
示例#5
0
 def evil() -> Any:
     nonlocal first_call
     if first_call:
         first_call = False
         return 42
     else:
         return trio.sleep(0)
示例#6
0
async def test_problems() -> None:
    async with open_service_nursery() as nursery:
        with pytest.raises(TypeError) as info:
            nursery.start_soon(trio.sleep)
        assert "missing 1 required positional argument" in str(info.value)

        with pytest.raises(TypeError) as info:
            nursery.start_soon(trio.sleep(1))  # type: ignore
        assert "Trio was expecting an async function" in str(info.value)

        with pytest.raises(TypeError) as info:
            nursery.start_soon(int, 42)  # type: ignore
        assert "appears to be synchronous" in str(info.value)

        first_call = True

        def evil() -> Any:
            nonlocal first_call
            if first_call:
                first_call = False
                return 42
            else:
                return trio.sleep(0)

        with pytest.raises(trio.TrioInternalError) as info:
            nursery.start_soon(evil)
        assert "all bets are off at this point" in str(info.value)
示例#7
0
async def parent():
    tasks = [(child, t) for t in range(2)]
    a = child(1)
    return await gather(
        child(1),
        child(2),
        trio.sleep(3),
    )
示例#8
0
def aio_sleep(seconds: float = 0) -> t.Awaitable:
    """Return sleep coroutine."""
    if trio and current_async_library() == 'trio':
        return trio.sleep(seconds)

    if curio and current_async_library() == 'curio':
        return curio.sleep(seconds)

    return asyncio.sleep(seconds)
示例#9
0
 async def receive_all(self, length=1024, bsize=None):
     buf = b''
     bsize = bsize if bsize is not None else 1024
     bsize = min(bsize, length)
     received = 0
     tries = 0
     while received < length:
         newbuf = await self.client_stream.receive_some(bsize)
         if not newbuf:
             # 3 successive read failure => raise exception
             if tries > 3:
                 raise IOError('Unable to read full response')
             tries += 1
             trio.sleep(0.1)
             continue
         # reset counter
         tries = 0
         buf += newbuf
         received += len(newbuf)
     return buf
示例#10
0
 async def receive_all(self, length=1024, bsize=None):
     buf = b""
     bsize = bsize if bsize is not None else 1024
     bsize = min(bsize, length)
     received = 0
     tries = 0
     while received < length:
         newbuf = await self.client_stream.receive_some(bsize)
         if not newbuf:
             # 3 successive read failure => raise exception
             if tries > 3:
                 raise IOError("Unable to read full response")
             tries += 1
             trio.sleep(0.1)
             continue
         # reset counter
         tries = 0
         buf += newbuf
         received += len(newbuf)
     return buf
示例#11
0
 async def example_child(depth):
     assert has_portal()
     await_(trio.sleep(0))
     if depth == 0:
         return
     async with trio.open_nursery() as nursery:
         nursery.start_soon(expect_portal)
         nursery.start_soon(greenback.with_portal_run_tree, example_child,
                            depth - 1)
         nursery.start_soon(example_child, depth - 1)
         await_(greenback.with_portal_run_tree(example_child, depth - 1))
         await trio.sleep(1)
示例#12
0
async def get_screenshot_data(driver, initial_delay=None):
    def get_image_height(filepath):
        ss_img = Image.open(filepath)
        height = ss_img.height
        ss_img.close()
        return height

    if initial_delay:
        trio.sleep(initial_delay)

    print(
        'todo: replace driver.get_full_document_screenshot() with driver.save_full_page_screenshot() (officially supported in selenium 4, which will be released soon)'
    )
    screenshot_fp = await driver.get_full_document_screenshot()
    screenshotQ_fp = await quantize_image(screenshot_fp)

    # height = get_image_height(screenshot_fp)
    height = await trio.to_thread.run_sync(get_image_height, screenshot_fp)

    return {
        'screenshot_fp': screenshot_fp,
        'screenshotQ_fp': screenshotQ_fp,
        'screenshot_height': height
    }
示例#13
0
 async def test(self):
     trio.sleep(0)
示例#14
0
 async def expect_portal():
     assert has_portal()
     await_(trio.sleep(0.5))
示例#15
0
 async def wrong_library():
     sniffio.current_async_library_cvar.set("tokio")
     with pytest.raises(RuntimeError,
                        match="greenback does not support tokio"):
         greenback.await_(trio.sleep(1))