python reference counting and exceptions

Gabriel Genellina gagsl-py at yahoo.com.ar
Tue Sep 12 20:53:52 EDT 2006


At Tuesday 12/9/2006 15:37, Andreas Huesgen wrote:

>In c++, it is possible to write a locking system similar to the one below:
>
>
>void myFunction()
>{
>         # create a resource lock. Locks some resource
>         ResourceLock myLock;
>
>         # the following line may throw an exception
>         doStuff();
>}
>
>
>My question is: is there some reliable way to mimic the c++ code snipped
>above in python without adding a try-except-unlock-rethrow block around
>every peace of code that locks some resources.

Yes: the try/finally construct, which is *not* the same as a 
try/except. The finally clause is always executed, whether or not an 
exception is raised.



Gabriel Genellina
Softlab SRL 


	
	
		
__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas




More information about the Python-list mailing list