下記のプログラムを実行した際に、"GPS情報"と"「ok」の表示"を並列処理させたかったのですが、「ok」がGPSとほぼ同時に表示されてしまい並列動作していることが確認できませんでした。
本来は、1秒毎にGPS表示しながら同時進行で2秒毎にokを表示させたかったのですがうまく動作しませんでした。
どこか不備が有ればおしえていただきたいです。
よろしくお願いします。。
python
1 2import time, datetime, threading, serial, micropyGPS 3 4gps = micropyGPS.MicropyGPS(9, 'dd') 5 6#関数------------------------------------------------------ 7def rungps(): 8 s = serial.Serial('/dev/serial0', 9600, timeout=10) 9 s.readline() 10 while True: 11 sentence = s.readline().decode('utf-8') 12 if sentence[0] != '$': 13 continue 14 for x in sentence: 15 gps.update(x) 16 17 if gps.clean_sentences > 20: 18 print('緯度経度: %2.8f, %2.8f' % (gps.latitude[0], gps.longitu$ 19 other() 20 time.sleep(1.0) 21#---------------------------------------------------------- 22 23def other(): 24 print('ok') 25 time.sleep(2.0) 26#---------------------------------------------------------- 27if __name__ == "__main__": 28 gpsthread = threading.Thread(target=rungps, args=()) 29 otherthread = threading.Thread(target=other) 30#gpsthread.daemon = True 31 gpsthread.start() 32 otherthread.start() 33
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/11/20 09:04
2018/11/21 00:24