On Mon, 15 Nov 1999, Marcelo Kallmann wrote:
... while ( true ) { for ( int i=0; i<n; i++ ) { restore_python_thread_state ( i ); // would call python functions to restore internal states, etc. run_some_bytecodes_of_python_script ( script[i] ); // would not block my loop, would not run all the script ! } .... }
So, first of all, my question is : Is this possible to do ?
Nope. Sorry. The Python interpreter runs to completion. It will not "unwind" and return to your loop. It uses *real* threads, and blocks on one to cause a context switch to another ready-thread. Well... more specifically, one thread grabs the global lock. Periodically, it releases it and re-acquires it. In that short time-frame when it doesn't hold the lock, another thread can wake up, grab it, and begin execution for a while. Cheers, -g -- Greg Stein, http://www.lyra.org/