Pythonicity of some algorithms

"Martin v. Löwis" martin at v.loewis.de
Sat May 10 06:21:02 EDT 2008


> This works for me. But I'd like to know if this is considered
> Pythonic, and if there are other, better ways of doing the above in
> Python.

>From the Python point of view, it's fine. However, it uses busy-wait,
which I consider bad style (in any language).

> 3) Make a custom thread-safe queue class, with an 'interrupt_get'
> method. When your app calls queue.interrupt_get(), all threads
> currently locking on a queue.get() will continue, but with a
> GetInterrupted exception thrown.

That's what I would do. I'd use the existing Queue class as a base
class, though, rather than starting from scratch.

Regards,
Martin



More information about the Python-list mailing list