Skip to content

Commit

Permalink
Re-implements the mutex usage so it does not depend on the 'with'
Browse files Browse the repository at this point in the history
clause. Since it was implemented on Python 2.6 there were some
production servers where it could not be executed - Debian stable
still ships Python 2.5, for instance.


git-svn-id: svn://cherokee-project.com/CTK/trunk@4881 5dc97367-97f1-0310-9951-d761b3857238
  • Loading branch information
alobbs committed Apr 19, 2010
1 parent a6784f1 commit ce51f22
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions CTK/Server.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,15 @@ def __cmp(x,y):
ly = len(y._regex)
return cmp(ly,lx)

with self.lock:
self.lock.acquire()
try:
self._web_paths.sort(__cmp)
finally:
self.lock.release()

def add_route (self, route_obj):
with self.lock:
self.lock.acquire()
try:
# Look for a duplicate
to_remove = []
for r in self._web_paths:
Expand All @@ -204,15 +208,20 @@ def add_route (self, route_obj):
# Insert
self._web_paths.append (route_obj)
self.sort_routes()
finally:
self.lock.release()

def remove_route (self, path):
with self.lock:
self.lock.acquire()
try:
to_remove = []
for r in self._web_paths:
if r._regex == path:
to_remove.append (r)

self._web_paths = filter (lambda x: x not in to_remove, self._web_paths)
finally:
self.lock.release()

def serve_forever (self):
try:
Expand Down

0 comments on commit ce51f22

Please sign in to comment.