junli_chen的博客

有总结才有进步!

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
想对作者说点什么? 我来说一句

Python--command模块

command模块

yanyangjie yanyangjie

2017-11-13 11:23:44

阅读数:240

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

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭