RotatingFileHandler + subprocess module problems

Gabriel Genellina gagsl-py at yahoo.com.ar
Thu Jan 11 21:57:11 EST 2007


At Thursday 11/1/2007 15:59, Stephen Hansen wrote:

>If I run app1, and then app2, it all works fine. Specifically, the 
>apps are logging correctly and I can see with Process Explorer that 
>each has a handle to the appropriate files.
>
>However, I have a setting to make App2 run App1 in the background 
>for convienance. This is using the subprocess module. When this 
>setting is on, App2 will die horribly the first time that the 
>doRollover comes along: specifically it gets a permission denied 
>error when it tries to rename App2.log to App2.log.1
>
>After doing some debugging, it appears that App1 (if started by App2 
>using the subprocess module) has a handle to App2.log /somehow/. It 
>never starts it, or touches it (verified through debug messages), 
>but seems to inherit it.

That's subprocess fault. You menctioned Process Explorer, it appears 
you're using Windows.
Using subprocess, the child process always inherits all file handles 
from its parent. This may or may not be desirable, and in your case, 
it's not. App1 inherits the open file handle to App2.log.
Inside subprocess.py, near line 789, there is a call to 
CreateProcess; its 5th parameter is called bInheritHandles and it's 
set to 1. The comment "must inherit handles to pass std handles" is 
wrong AFAIK, and setting STARTF_USESTDHANDLES in startupinfo   should 
be enough. (It may be that some lines above, STARTF_USESTDHANDLES is 
not correctly set).
I'll try to investigate a bit more and file a bug report or a patch.
In the meantime, you could replace that 1 in CreateProcess by a 0. 
Specially if you don't use PIPE or redirects, your problem should go away.


-- 
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