Commits

Anonymous committed 17634f5

catch keyboard interrupt and resize datasets

  • Participants
  • Parent commits 677166d

Comments (0)

Files changed (1)

File tektronix.py

             fastframe_count = int(scope.query('horizontal:fastframe:count?'))
 
             i = 0
-            while i < options.nevents:
-                print '\rsaving event: %i' % (i+1),
-                sys.stdout.flush()
+            try:
+                while i < options.nevents:
+                    print '\rsaving event: %i' % (i+1),
+                    sys.stdout.flush()
 
-                scope.acquire()
+                    scope.acquire()
 
-                if fastframe_state:
-                    n = min(fastframe_count,options.nevents-i)
-                else:
-                    n = 1
+                    if fastframe_state:
+                        n = min(fastframe_count,options.nevents-i)
+                    else:
+                        n = 1
+
+                    for channel in active_channels:
+                        dataset = f['channel%i' % channel]
+
+                        data = scope.get_waveform(channel, dataset.dtype)
+
+                        if fastframe_state:
+                            data = data.reshape((fastframe_count,-1))
+                            dataset[i:i+n] = data[:n]
+                        else:
+                            dataset[i] = data
+
+                    i += n
+            except KeyboardInterrupt:
+                print
+                print 'resizing datasets...'
 
                 for channel in active_channels:
                     dataset = f['channel%i' % channel]
-
-                    data = scope.get_waveform(channel, dataset.dtype)
-
-                    if fastframe_state:
-                        data = data.reshape((fastframe_count,-1))
-                        dataset[i:i+n] = data[:n]
-                    else:
-                        dataset[i] = data
-
-                i += n
-
-            print
+                    dataset.resize((i,dataset.shape[1]))
+            else:
+                print
 
         elapsed = time.time() - t0