小编Art*_*ais的帖子

从sys.stdin获取输入,非阻塞

我正在研究一个竞争机器人,它通过sys.stdin接收'输入,并使用Python的print()输出.我有以下内容:

import sys

def main():
    while True:
        line = sys.stdin.readline()
        parts = line.split()
        if len(parts) > 0:
            # do stuff
Run Code Online (Sandbox Code Playgroud)

问题是输入是通过流进入的,使用上面的方法阻止我打印任何东西直到流关闭.我能做些什么来完成这项工作?

python input

15
推荐指数
3
解决办法
3万
查看次数

写入/读取协议缓冲区

为了通过线路将复杂的 JSON/JavaScript 对象发送到 C++ 二进制文件,我使用了 Protocol Buffers。如今,Node.js 有原生 protobuf 支持,因此我没有使用任何其他绑定。

// Set maximum execution time of binary to equal the
// remainder of processing time, minus a second to allow
// for parsing.
var timeLimit = context.getRemainingTimeInMillis() - 1000;

// Check if meta parameters are given in the request.
// Assign default values if they are not.
var model = new protocols.Model();

// Sort the resolutions.
function descending(a, b) {
    if (a.width > b.width) {
        return -1;
    } else if …
Run Code Online (Sandbox Code Playgroud)

javascript protocol-buffers

5
推荐指数
1
解决办法
4129
查看次数

标签 统计

input ×1

javascript ×1

protocol-buffers ×1

python ×1