我有两个连接到我的Linux机器的Android设备,我需要能够同时在两者上截取屏幕截图。我怎么能在python中实现这一点? 这就是我到目前为止所做的:
import time, datetime
from threading import Thread
from Queue import Queue
def get_screenshot(deviceid):
print deviceid
print datetime.datetime.now()
# Logic to get screenshot goes here
deviceids = ["blabla1", "blabla2"]
q = Queue()
for d in deviceids:
t = Thread(target=get_screenshot, args=(d,))
t.setDaemon(True)
t.start()
for d in deviceids:
q.put(d)
q.join()
输出如下:
blabla1
2016-10-02 12:55:17.146964
blabla2
2016-10-02 12:55:17.147141
问题是: 1.方法是否正确? 2.为什么相差1ms?可以避免吗? 3.该程序不退出。我需要 Ctrl + Z 。
答案 0 :(得分:0)
import datetime
from threading import Thread
def get_screenshot(deviceid):
print("%s %s" %(deviceid, datetime.datetime.now()))
deviceids = ["blabla1", "blabla2"]
for d in deviceids:
t = Thread(target=get_screenshot, args=(d,))
t.start()