在python中,shell脚本中的“&”等价于什么

2024-09-29 20:29:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我在shell脚本上有一个这样写的脚本

function test1(){ command1 };
function test2(){ command2 };
function test3(){ command3 };

我使用shell脚本上的&来运行那些daemonized writing test1 & test2 & test3函数

但是我想在Python上做同样的事情。有没有一种方法可以使用任何python内置函数而不使用“daemonize”库?你知道吗

编辑:我想我应该写得更好。我现在知道“背景”是这个问题的更好的词了。我的意图是将我读到的here与python命令结合起来,使某些东西像daemonized一样。 tripleeecomment已经帮我回答了。你知道吗

感谢所有留言的人,并对错误表示歉意。你知道吗

因为我没有足够的声誉,所以我不能给分或添加评论。你知道吗


Tags: 方法函数脚本functionshell事情内置test1
1条回答
网友
1楼 · 发布于 2024-09-29 20:29:19

Python^{} module允许您同时运行多个进程,就像shell的后台作业一样。你知道吗

from multiprocessing import Process

if __name__ == '__main__':
    t1 = Process(target=test1, args=('bob',))
    t1.start()
    t2 = Process(target=example2)
    t2.start()
    t3 = Process(target=demo3, args=('steve jobs', 'bill gates'))
    t3.start()
    # ... Do other stuff

。。。其中test1example2demo3是希望与主/父进程同时运行的Python函数。你知道吗

如果不想并行运行Python代码,subprocess.Popen()将创建一个进程,独立于Python程序运行外部命令。你知道吗

相关问题 更多 >

    热门问题