[FIX] core: correcly handle pidfile deletion.

As atexit function are inherited by subprocess, the pidfile was always
deleted when the first worker (http or cron) died. Now, only the
process that created the pidfile will delete it.
This commit is contained in:
Christophe Simonis 2015-11-26 10:40:59 +01:00
parent b459c4dc03
commit 78ea8eb058
1 changed files with 5 additions and 5 deletions

View File

@ -80,9 +80,9 @@ def report_configuration():
('database user', config['db_user'])]: ('database user', config['db_user'])]:
_logger.info("%s: %s", name, value) _logger.info("%s: %s", name, value)
def rm_pid_file(): def rm_pid_file(main_pid):
config = openerp.tools.config config = openerp.tools.config
if not openerp.evented and config['pidfile']: if config['pidfile'] and main_pid == os.getpid():
try: try:
os.unlink(config['pidfile']) os.unlink(config['pidfile'])
except OSError: except OSError:
@ -95,10 +95,10 @@ def setup_pid_file():
""" """
config = openerp.tools.config config = openerp.tools.config
if not openerp.evented and config['pidfile']: if not openerp.evented and config['pidfile']:
pid = os.getpid()
with open(config['pidfile'], 'w') as fd: with open(config['pidfile'], 'w') as fd:
pidtext = "%d" % (os.getpid()) fd.write(str(pid))
fd.write(pidtext) atexit.register(rm_pid_file, pid)
atexit.register(rm_pid_file)
def export_translation(): def export_translation():