I have a python script whihc logs in some file.
This script calls some outside bat file which also logs in same file. The out side program complains that it cant get lock on log file.
The python script has lock to log file so it has to temporarily release. So before calling outside program, I call logging.shutdown, It works fine and out side program can log in log file but once control is returned to python script, I try to acquire another logging.getLogger() but it throws exception "Error: cannot release un-aquired lock" and script exits. The weird thing is that , the line 'i m fine is printed twice before script exits. I am printing it only once in my script. Any idea what is going on and how can I resolve this issue.

Here is my code snippet

#some python work
logging.shutdown()
process = subprocess.Popen(...)
process.wait()
configure_logger()
logger.info(' i m fine')
#some more python work

def configure_logger():   
   
   global logger
   
   logging.basicConfig(level=logging.DEBUG,
                      format="[%(asctime)s ''  %(levelname)s]  [%(name)s]  %(message)s",
                      datefmt='%m-%d-%Y %H:%M:%S:%MS',
                      filename=LOG_FILENAME)

   console = logging.StreamHandler()
   console.setLevel(logging.INFO)
   print ' i m trying 5'
   logger = logging.getLogger('vum_backup')
   logger.addHandler(console)

Not exactly sure by looking at the code, but from what you said you let python release first then let the other process access the file, but you didn't say anything about doin the same for that process to release the file for python. It's definatly gonna roll both ways.

Not exactly sure by looking at the code, but from what you said you let python release first then let the other process access the file, but you didn't say anything about doin the same for that process to release the file for python. It's definatly gonna roll both ways.

That process has terminated so lock is available for python.

Seems like when you call logging.shutdown , you lose all logging capability. Is there any other way, we can release lock on log file from python

I have a python script whihc logs in some file.
This script calls some outside bat file which also logs in same file.

What does that .bat script do that can't be done in python?
IMHO, Python is very capable of replacing your .bat and hence removing unnecessary snags. Also Python OOP capabilities are added advantages

This article has been dead for over six months. Start a new discussion instead.