changeset 2075:bec08e9236f5

more robust AutoClassify.py sample
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 16 Aug 2016 12:49:38 +0200
parents 4a151d26c98a
children ec2ad6ac741e
files Resources/Samples/Python/AutoClassify.py
diffstat 1 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/Resources/Samples/Python/AutoClassify.py	Tue Aug 16 11:28:31 2016 +0200
+++ b/Resources/Samples/Python/AutoClassify.py	Tue Aug 16 12:49:38 2016 +0200
@@ -110,13 +110,17 @@
         if change['ChangeType'] == 'NewInstance':
             try:
                 ClassifyInstance(change['ID'])
+
+                # If requested, remove the instance once it has been
+                # properly handled by "ClassifyInstance()". Thanks to
+                # the "try/except" block, the instance is not removed
+                # if the "ClassifyInstance()" function fails.
+                if args.remove:
+                    RestToolbox.DoDelete('%s/instances/%s' % (URL, change['ID']))
+
             except:
                 print('Unable to write instance %s to the disk' % change['ID'])
 
-            # If requested, remove the instance once it has been copied
-            if args.remove:
-                RestToolbox.DoDelete('%s/instances/%s' % (URL, change['ID']))
-
     current = r['Last']
 
     if r['Done']: