小编Ngu*_*inh的帖子

在C++中将范围分配给变量

看看这段代码,有人可以解释一下为什么a+1;分配给我b

#include <iostream>

int main(int argc, char *argv[])
{
  int a = 5;

  int b = ({
      std::cout << "inside scope" << std::endl;
      a+1;
  });

  std::cout << "b value: " << b;
}
Run Code Online (Sandbox Code Playgroud)

c++ gcc

4
推荐指数
1
解决办法
87
查看次数

Python asyncio子进程连续写入stdin和读取stdout / stderr

我目前正在使用python3 asyncio中的子流程执行任务。我的代码只是简单地写入stdin并同时读取stdout / stderr:

import asyncio


async def read_stdout(stdout):
    print('read_stdout')
    while True:
        buf = await stdout.read(10)
        if not buf:
            break

        print(f'stdout: { buf }')


async def read_stderr(stderr):
    print('read_stderr')
    while True:
        buf = await stderr.read()
        if not buf:
            break

        print(f'stderr: { buf }')


async def write_stdin(stdin):
    print('write_stdin')
    for i in range(100):
        buf = f'line: { i }\n'.encode()
        print(f'stdin: { buf }')

        stdin.write(buf)
        await stdin.drain()
        await asyncio.sleep(0.5)


async def run():
    proc = await asyncio.create_subprocess_exec(
        '/usr/bin/tee',
        stdin=asyncio.subprocess.PIPE,
        stdout=asyncio.subprocess.PIPE,
        stderr=asyncio.subprocess.PIPE)

    await asyncio.gather(
        read_stderr(proc.stderr),
        read_stdout(proc.stdout), …
Run Code Online (Sandbox Code Playgroud)

python subprocess python-3.x python-asyncio

4
推荐指数
1
解决办法
283
查看次数

标签 统计

c++ ×1

gcc ×1

python ×1

python-3.x ×1

python-asyncio ×1

subprocess ×1