0

我想创建一个bash(或者zsh,没关系。)服务器,它接受命令,运行它们并返回结果(return code, stdout, stderr)。我的目的是避免为我想在脚本中运行bash的每个命令启动一个新实例,因为我的点文件需要很长时间才能加载。本着以下精神的东西:bashPythonbash

bash = bash_instance() # pay the startup penalty ONCE
bash.run('echo hi') # Just run the command without the startup time
...
bash.run('curl ipinfo.io')
return_code, stdout, stderr = bash.run('cat file.txt')

一种Remote Method Call为壳。

4

1 回答 1

0

您可以使用多处理

from multiprocessing import Pool

zsh = zsh_instance()

with Pool(5) as p:
    print(p.map(zsh.run, [
        ('some-command',),
        ('some-other-command',)
    ]))
于 2020-04-12T17:06:30.093 回答