python - 是否可以从服务中使用相同的 gnome 终端窗口

标签 python python-3.x ubuntu-18.04 gnome-terminal

我可以从 python 服务打开一个终端来跟踪我想要的某些文件。但是,如果我想按顺序尾随许多文件,以下代码将为每个文件启动一个新终端。如何强制始终重复使用相同的终端窗口?

def tail_logging(title, file_to_tail):
    os.system(
        "DISPLAY=:0.0 XAUTHORITY=/data/.Xauthority gnome-terminal --name 'Todd' -t "
        + title
        + ' -- /bin/bash -c "tail -f '
        + file_to_tail
        + '"'
    )

for i in range(3):
    tail_logging("Same", str(i))

enter image description here

最佳答案

由于我需要使其尽快运行,因此这是我的解决方法。我跟踪主日志(最初为空)并让其他进程写入其自己的日志以及该主日志。为了同时写入两个日志文件,我只需在记录器中创建 2 个文件处理程序。它运作得很好。我现在可以在同一终端控制台中查看来自不同进程的日志。

关于python - 是否可以从服务中使用相同的 gnome 终端窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55081415/

相关文章:

python - Pandas 计算日期时间差异,但针对每个用户

python - ValueError : Error when checking input: expected conv2d_3_input to have shape (100, 100, 1) 但得到形状为 (100, 100, 3) 的数组

python-3.x - 从网络中的数据帧向节点添加属性

c++ - 为什么我使用 std::variant 获得 std::bad_variant_access?

php - 如果mysql查询执行时间较长,如何停止执行

linux - Ubuntu 18.04 : Cannot extract downloaded tar. xz 文件用单个命令

python - 缺少预期输出

python - 当第一个参数大于第二个参数时,range() 返回空列表

python - 如何安装matplotlib? [Python]

python - 按列分组并将另一列的值分散到其他列中