Boost logo

Boost :

From: Ullrich Koethe (u.koethe_at_[hidden])
Date: 2001-06-25 18:36:11


dustin_at_[hidden] wrote:
>
> Thank you for your reply. Here is what I want to accomplish:
>
> 1. A long running C++ method within the extension module monitors a
> flag, and exits if the flag is true.
> 2. A seperate python thread sets the flag when the user hits a cancel
> button.
>
> In order to do this, I will have to release the interpreter lock, so
> that the user interface thread can execute. Can I safely set a
> boolean value within the extension module from the user interface
> thread while the main thread executes within the extension module?
>

The cleanest solution might be this: let the button call
"PyErr_SetInterrupt()" when pressed (of course, the GUI thread must hold
the Python lock to do this). Then, in the other thread (long C++
algorithm) regularly re-aquire the Python lock and call
"PyOS_InterruptOccurred()". Throw an exception if this call returns true
(e.g. throw std::runtime_error("User interrupt")). Note that the C++
algorithm must not invoke either Python or GUI functions while it
doesn't hold the lock.

Ulli

-- 
 ________________________________________________________________
|                                                                |
| Ullrich Koethe  Universität Hamburg / University of Hamburg    |
|                 FB Informatik / Dept. of Computer Science      |
|                 AB Kognitive Systeme / Cognitive Systems Group |
|                                                                |
| Phone: +49 (0)40 42883-2573                Vogt-Koelln-Str. 30 |
| Fax:   +49 (0)40 42883-2572                D - 22527 Hamburg   |
| Email: u.koethe_at_[hidden]               Germany             |
|        koethe_at_[hidden]                        |
| WWW:   http://kogs-www.informatik.uni-hamburg.de/~koethe/      |
|________________________________________________________________|

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk