Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/debian/patches/1003_avoid_with_statement.patch
blob: 8e0f44254af73b4d0968963fb5db33a997b4fd60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
diff --git a/src/olpc/datastore/xapianindex.py b/src/olpc/datastore/xapianindex.py
index 888bd26..c2506cb 100644
--- a/src/olpc/datastore/xapianindex.py
+++ b/src/olpc/datastore/xapianindex.py
@@ -4,8 +4,6 @@ xapianindex
 maintain indexes on content
 
 """ 
-from __future__ import with_statement
-
 __author__ = 'Benjamin Saller <bcsaller@objectrealms.net>'
 __docformat__ = 'restructuredtext'
 __copyright__ = 'Copyright ObjectRealms, LLC, 2007'
@@ -173,7 +170,8 @@ class IndexManager(object):
 
         self.deltact += 1
         if force or self.deltact > FLUSH_THRESHOLD:
-            with self._write_lock:
+            self._write_lock.acquire()
+            try:
 
                 # TODO: Would be better to check if the device is present and
                 # don't try to flush if it's not.
@@ -185,6 +183,8 @@ class IndexManager(object):
 
                 #self.read_index.reopen()
                 self.deltact = 0
+            finally:
+                self._write_lock.release()
         else:
             self._flush_timeout = gobject.timeout_add(FLUSH_TIMEOUT * 1000,
                                                       self._flush_timeout_cb)
@@ -196,13 +196,16 @@ class IndexManager(object):
         # conversion/fulltext indexing can
         # happen in the thread
         if operation in (CREATE, UPDATE):
-            with self._write_lock:
+            self._write_lock.acquire()
+            try:
                 if operation is CREATE:
                     self.write_index.add(doc)
                     logger.info("created %s:%s" % (uid, vid))
                 elif operation is UPDATE:
                     self.write_index.replace(doc)
                     logger.info("updated %s:%s" % (uid, vid))
+            finally:
+                self._write_lock.release()
             self.flush()
 
             # Disable content indexing for Trial-3.
@@ -217,9 +220,12 @@ class IndexManager(object):
                 return
         elif operation is DELETE:
             # sync deletes
-            with self._write_lock:
+            self._write_lock.acquire()
+            try:
                 self.write_index.delete(uid)
                 logger.info("deleted content %s:%s" % (uid,vid))
+            finally:
+                self._write_lock.release()
             self.flush()
             return
 
@@ -246,7 +252,8 @@ class IndexManager(object):
                 continue
 
             try:
-                with self._write_lock:
+                self._write_lock.acquire()
+                try:
                     if operation is UPDATE:
                         # Here we handle the conversion of binary
                         # documents to plain text for indexing. This is
@@ -276,6 +283,8 @@ class IndexManager(object):
 
                     # tell the queue its complete 
                     self.queue.task_done()
+                finally:
+                    self._write_lock.release()
 
                 # we do flush on each record now
                 self.flush()
@@ -336,8 +345,11 @@ class IndexManager(object):
             d[p.key] = p
 
         if add_anything:
-            with self._write_lock:
+            self._write_lock.acquire()
+            try:
                 self.datamodel.apply(self)
+            finally:
+                self._write_lock.release()
             
         return d