Fix warnings and crash in snapshot app and update changelog

Bug: 143085486, 142978423, 143091023
Change-Id: I56fdba91ad1743ed6721372f39e8763bb3c2989f
Signed-off-by: Leonid Lobachev <leonidl@google.com>
diff --git a/debian/changelog b/debian/changelog
index 4f9ca97..80d1ca6 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+imx-board-tools (6-2) mendel-day; urgency=medium
+
+  * Fix warnings and crash in snapshot app.
+
+ -- Coral <coral-support@google.com>  Mon, 21 Oct 2019 14:48:32 -0700
+
 imx-board-tools (6-1) mendel-day; urgency=medium
 
   * Cut for day release.
diff --git a/snapshot b/snapshot
index 247f0cc..30dffdc 100755
--- a/snapshot
+++ b/snapshot
@@ -7,6 +7,7 @@
 import select
 import sys
 import termios
+import time
 import threading
 
 import gi
@@ -17,7 +18,6 @@
 from gi.repository import GLib, GObject, Gst, GstBase
 from PIL import Image
 
-GObject.threads_init()
 Gst.init(None)
 
 FILENAME_PREFIX = 'img'
@@ -114,7 +114,7 @@
   appsink = pipeline.get_by_name('appsink')
   appsink.connect('new-sample', partial(on_new_sample, snapinfo=snapinfo))
 
-  loop = GObject.MainLoop()
+  loop = GLib.MainLoop()
 
   # Set up a pipeline bus watch to catch errors.
   bus = pipeline.get_bus()
@@ -164,12 +164,12 @@
     self.num = 0
     self.scrapframes = SCRAP_FRAMES
     self.sysfs = sysfs
+    self.loop = None
 
     if not oneshot:
       self.pipe_r, self.pipe_w = os.pipe()
-      thread = threading.Thread(target=self.read_keyboard)
-      thread.daemon = True
-      thread.start()
+      self.thread = threading.Thread(target=self.read_keyboard)
+      self.thread.daemon = True
 
   def get_filename(self):
     while True:
@@ -193,6 +193,8 @@
         if c == 'r':
           self.refocus()
         if c == 'q':
+          while not self.loop.is_running():
+            time.sleep(0.01)
           self.loop.quit()
           break
 
@@ -242,6 +244,7 @@
 
   def connect_loop(self, loop):
     self.loop = loop
+    self.thread.start()
 
 
 def main(arguments):