小编Soh*_*aha的帖子

如何在Python3中同时进行并行输入和输出?

我需要设计一个脚本,该脚本使用终端的顶部部分作为输出,其中在无限循环中每秒打印一些行,底部部分不断接受用户输入并在上面的部分中打印它们(在常规周期中)输出)。

换句话说,我需要设计一种外壳。

我尝试使用简单的方法进行多线程处理,如下所示:

#!/usr/bin/python3

from math import acos
from threading import Thread
from random import choice
from time import sleep
from queue import Queue, Empty

commandQueue = Queue()

def outputThreadFunc():
    outputs = ["So this is another output","Yet another output","Is this even working"] # Just for demo
    while True:
        print(choice(outputs))
        try:
            inp = commandQueue.get(timeout=0.1)
            if inp == 'exit':
                return
            else:
                print(inp)
        except Empty:
            pass        
        sleep(1)

def inputThreadFunc():
    while True:
        command = input("> ") # The shell
        if command == 'exit':
            return …
Run Code Online (Sandbox Code Playgroud)

python shell multithreading python-multithreading python-3.x

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

无法在 React Three Fiber 中旋转网格

我有一个平面网格,我想用初始旋转向量对其进行初始化。但是,设置rotateXprop 不起作用。

<mesh rotateX={1}>
   <planeGeometry args={[5, 5, 64, 64]} />
   <meshStandardMaterial />
</mesh>
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

three.js reactjs react-three-fiber react-three-drei

4
推荐指数
2
解决办法
7407
查看次数