|
- #coding:utf8
- from ping import quiet_ping as myping
- import threading , time
- def ping_process(dest_addr, timeout=2, count=4, psize=64):
- print myping(dest_addr, timeout, count, psize)
- #单线程
- ip = ['114.114.114.114','114.114.113.112']
- for i in ip:
- ping_process(i)
- #多线程
- threads = []
- for i in ip:
- threads.append(threading.Thread(target=ping_process,args=(i,)))
- for t in threads:
- t.setDaemon(True)
- t.start()
- # time.sleep(1)
- for i in threads:
- i.join()
- print 'end'
复制代码 windows下结果正确
(0, 16.000032424926758, 4.0000081062316895)
(100, None, None)
[<Thread(Thread-1, initial)>, <Thread(Thread-2, initial)>]
(0, 16.000032424926758, 4.249989986419678)
(100, None, None)
end
[Finished in 17.1s]
liunx下结果错误
(0, 5.9680938720703125, 5.356550216674805)
(100, None, None)
[<Thread(Thread-1, initial)>, <Thread(Thread-2, initial)>]
(0, 5.489110946655273, 5.181312561035156)
(0, 5.569934844970703, 5.251467227935791)
end
试过threading.local()什么的,都无法解决。求大神解答
|
|