Improved locking mechanism in decoder

master
Sven Steudte 2018-08-18 02:50:53 +02:00
rodzic ce33762ae1
commit 79cfbefa96
2 zmienionych plików z 20 dodań i 18 usunięć

Wyświetl plik

@ -171,7 +171,7 @@ if args.device == 'I': # Source APRS-IS
else: # Data handling
received_data(buf)
time.sleep(0.01)
#time.sleep(0.001)
elif args.device is '-': # Source stdin

Wyświetl plik

@ -40,22 +40,23 @@ def imgproc():
global imageData
while True:
imageDataCpy = {}
with lock:
for _id in imageData:
(call, data) = imageData[_id]
filename = 'html/images/%s-%d.jpg' % (call.replace('-',''), _id)
f = open(filename, 'wb')
process = Popen(['./ssdv', '-d'], stdin=PIPE, stdout=f, stderr=PIPE)
process.stdin.write(data)
dummy,err = process.communicate()
f.close()
filename2 = 'html/images/%s.jpg' % (call.replace('-',''))
copyfile(filename, filename2)
imageDataCpy = imageData
imageData = {} # Clear data
for _id in imageDataCpy:
(call, data) = imageDataCpy[_id]
filename = 'html/images/%s-%d.jpg' % (call.replace('-',''), _id)
f = open(filename, 'wb')
process = Popen(['./ssdv', '-d'], stdin=PIPE, stdout=f, stderr=PIPE)
process.stdin.write(data)
dummy,err = process.communicate()
f.close()
filename2 = 'html/images/%s.jpg' % (call.replace('-',''))
copyfile(filename, filename2)
time.sleep(1)
w = time.time()
@ -120,11 +121,12 @@ def insert_image(db, receiver, call, data_b91):
db.commit()
w = time.time()
allData = ''
cur.execute("SELECT `data` FROM `image` WHERE `id` = %s ORDER BY `packetID`", (_id,))
for data, in cur.fetchall():
allData += '55' + data + (144*'0')
with lock:
allData = ''
cur.execute("SELECT `data` FROM `image` WHERE `id` = %s ORDER BY `packetID`", (_id,))
for data, in cur.fetchall():
allData += '55' + data + (144*'0')
imageData[_id] = (call, binascii.unhexlify(allData))
if imageProcessor is None: