use lock on Browser

This commit is contained in:
Romain Bignon 2010-04-27 01:14:34 +02:00
commit ad240e7aed
2 changed files with 36 additions and 27 deletions

View file

@ -18,6 +18,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
""" """
from __future__ import with_statement
from weboob.backend import BaseBackend from weboob.backend import BaseBackend
from weboob.capabilities.messages import ICapMessages, ICapMessagesReply from weboob.capabilities.messages import ICapMessages, ICapMessagesReply
from weboob.capabilities.dating import ICapDating from weboob.capabilities.dating import ICapDating
@ -67,6 +69,7 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesReply, ICapDating):
yield message yield message
def _iter_messages(self, thread, only_new): def _iter_messages(self, thread, only_new):
with self.browser:
try: try:
if not only_new or self.browser.nb_new_mails(): if not only_new or self.browser.nb_new_mails():
my_name = self.browser.get_my_name() my_name = self.browser.get_my_name()
@ -94,10 +97,12 @@ class AuMBackend(BaseBackend, ICapMessages, ICapMessagesReply, ICapDating):
def post_reply(self, thread_id, reply_id, title, message): def post_reply(self, thread_id, reply_id, title, message):
for message in self._iter_messages(thread_id, True): for message in self._iter_messages(thread_id, True):
self.queue_messages.append(message) self.queue_messages.append(message)
with self.browser:
return self.browser.post(thread_id, message) return self.browser.post(thread_id, message)
def get_profile(self, _id): def get_profile(self, _id):
try: try:
with self.browser:
return self.browser.get_profile(_id) return self.browser.get_profile(_id)
except BrowserUnavailable: except BrowserUnavailable:
return None return None

View file

@ -18,6 +18,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
""" """
from __future__ import with_statement
from logging import debug from logging import debug
from random import randint from random import randint
from weboob.tools.browser import BrowserUnavailable from weboob.tools.browser import BrowserUnavailable
@ -42,6 +44,7 @@ class ProfilesWalker(object):
self.event = None self.event = None
def walk(self): def walk(self):
with self.browser:
self.profiles_queue = self.profiles_queue.union(self.browser.search_profiles()).difference(self.visited_profiles) self.profiles_queue = self.profiles_queue.union(self.browser.search_profiles()).difference(self.visited_profiles)
self.save() self.save()
@ -53,6 +56,7 @@ class ProfilesWalker(object):
return # empty queue return # empty queue
try: try:
with self.browser:
profile = self.browser.get_profile(id) profile = self.browser.get_profile(id)
debug(u'Visited %s (%s)' % (profile.get_name(), id)) debug(u'Visited %s (%s)' % (profile.get_name(), id))