[weboob] Threads in weboob

Romain Bignon romain at peerfuse.org
Tue Apr 27 01:29:45 CEST 2010

On 26/Apr - 19:50, Christophe Benz wrote:
> Hi,
> I agree with this idea.
> I have no time to answer in details, but let's do the job!

Right, I started to work on it. It works fine with the videoob frontend.

The API is:

	for backend, result in self.weboob.do('iter_search_results', pattern):
		# process

Weboob.do creates a BackendsCall object, which starts a thread for every
backend.  The __iter__ method waits for new responses, and yield a Result object
each time there is a response.

The Result object has an __iter__ attribute, it is usefull to do:
	backend, result = self.weboob.do(...)

There is also a Weboob.do_caps() method to do operations only on backends with
specific capabilities.

I also created a method 'callback_thread' method in BackendsCall. You can use it
if you want to have a function called in a thread each time a new results
arrives. For example, in a Qt application:

	def cb(backend, result):
		Qt.emit(Qt.SIGNAL('new_result', backend, result))

	c = self.weboob.do('iter_search_results', pattern)

The 'thread' in method is important to keep in mind that the callback will be
called in a separated thread.

Another thing, now Backend and Browser classes are protected with a mutex which
can be locked if you want. Note that if you want to use them safely, it is
recommanded to use the 'with' statement:

	with backend:

The backend's mutex is locked when entering in the 'with' bloc, and released
when leaving it, even if an exception is raised.

Now, a big problem is about exceptions when you call Weboob.do. A backend's
method can raise legitimate exception to be catched on frontend.

But with this new API, there is no way to catch a global backend exception,
because the frontend get results regardless of backends order.

Any idea?

(Note: I'm tired)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 489 bytes
Desc: not available
URL: <https://lists.symlink.me/pipermail/weboob/attachments/20100427/21560f47/attachment.sig>

More information about the weboob mailing list