Python os.system(command),这样执行的command命令,和主程序是异步的吗?

Python os.system(command),这样执行的command命令,和主程序是异步的吗?

是同步执行的。
尚未执行完成的情况下,下面的程序不会继续操作。
看下面的例子即可:
>>> import os
>>> def test():
...     print '1111'
...     os.system('ping 127.0.0.1')
...     print '2222'
...     os.system('ping 127.0.0.1')
...     print '3333'
...
>>> test()
1111
Pinging 127.0.0.1 with 32 bytes of data:
Reply from 127.0.0.1: bytes=32 time<1ms TTL=64
Reply from 127.0.0.1: bytes=32 time<1ms TTL=64
Reply from 127.0.0.1: bytes=32 time<1ms TTL=64
Reply from 127.0.0.1: bytes=32 time<1ms TTL=64
Ping statistics for 127.0.0.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms
2222
Pinging 127.0.0.1 with 32 bytes of data:
Reply from 127.0.0.1: bytes=32 time<1ms TTL=64
Reply from 127.0.0.1: bytes=32 time<1ms TTL=64
Reply from 127.0.0.1: bytes=32 time<1ms TTL=64
Reply from 127.0.0.1: bytes=32 time<1ms TTL=64
Ping statistics for 127.0.0.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms
3333
>>>


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/junli_chen/article/details/56835578
个人分类: python
上一篇在项目中的总结
下一篇mac地址是唯一不变的吗?
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭