Index: trunk/ippToPsps/jython/ipptopspsdb.py
===================================================================
--- trunk/ippToPsps/jython/ipptopspsdb.py	(revision 35097)
+++ trunk/ippToPsps/jython/ipptopspsdb.py	(revision 35175)
@@ -1168,5 +1168,5 @@
             rs.close()
         except:
-            self.logger.errorPair("No free stripes", "trying to share with other client...")
+            self.logger.errorPair("No free stripes", "trying to steal boxes from other client...")
             sql = "SELECT ra_center, COUNT(*) AS numPending\
                    FROM box \
@@ -1184,5 +1184,5 @@
                 rs.close()
             except:
-                self.logger.errorPair("No available stripes to share", "no stripe obtained")
+                self.logger.errorPair("No outstanding boxes to steal", "no stripe obtained")
 
         self.logger.infoPair("Using RA stripe", "%f" % raCenter)
@@ -1203,4 +1203,67 @@
 
         self.registerStripe(host, pid, raCenter)
+
+        self.unlockTables()
+
+        return ids
+
+    '''
+    Returns ids for all boxes with pending items in a stripe of RA not already being processed
+    by another client. If none are available, then it uses the stripe already used by another 
+    client that has the most pending items
+    '''
+    def getStripeBoxIdsAnyBatch(self, host, pid):
+
+        self.execute("LOCK TABLES box READ, pending READ, stripe WRITE, clients WRITE")
+
+        ids = []
+        raCenter = -1.0
+        sql = "SELECT ra_center \
+               FROM box \
+               JOIN pending ON (id = box_id) \
+               WHERE skychunk = '" + self.skychunk.name + "' \
+               AND ra_center NOT IN \
+               (SELECT ra_center \
+                FROM stripe \
+                WHERE skychunk = '" + self.skychunk.name + "') \
+               GROUP BY ra_center LIMIT 1"
+
+        try:
+            rs = self.executeQuery(sql)
+            rs.first()
+            raCenter = rs.getFloat(1)
+            rs.close()
+        except:
+            self.logger.errorPair("No free stripes", "trying to steal boxes from other client...")
+            sql = "SELECT ra_center, COUNT(*) AS numPending\
+                   FROM box \
+                   JOIN pending ON (id = box_id) \
+                   WHERE skychunk = '" + self.skychunk.name + "' \
+                   GROUP BY ra_center \
+                   ORDER BY numPending \
+                   DESC LIMIT 1"
+
+            try:
+                rs = self.executeQuery(sql)
+                rs.first()
+                raCenter = rs.getFloat(1)
+                rs.close()
+            except:
+                self.logger.errorPair("No outstanding boxes to steal", "no stripe obtained")
+
+        self.logger.infoPair("Using RA stripe", "%f" % raCenter)
+        sql = "SELECT DISTINCT id \
+               FROM box \
+               JOIN pending ON (id = box_id) \
+               WHERE ra_center = " + str(raCenter) + " \
+               AND skychunk = '" + self.skychunk.name + "' \
+               ORDER BY dec_center DESC"
+
+        try:
+            rs = self.executeQuery(sql)
+            while (rs.next()): ids.append(rs.getInt(1))
+            rs.close()
+        except:
+            self.logger.errorPair("Can't get stripe boxes", sql)
 
         self.unlockTables()
