I run 2 python scripts from crontab at the same time each 30 min, e.g.
00,30 6-19 * * 0-5 /.../x.py site1
*/3 6-19 * * 0-5 /.../y.py site2
At the beginning the both scripts make import of a module that prints some data to a log, e.g.
name = os.path.basename(sys.argv[0])
site = sys.argv[1]
pid = os.getpid()
Occasionally (!) the second script y prints to the log input arguments of script x: name = x and site = site1 printed PID of the processes is not the same. Why this is happening and how can i avoid this?
P.S. I suspect the problem is related to the logger I use. Can a script use a logger created in another script? In this case it will print on each line data related to the first script. Each script executes the same code:
log = logging.getLogger('MyLog')
log.setLevel(logging.INFO)
dh = RotatingSqliteHandler(os.path.join(progDirs['log'],'sqlitelog'),processMeta, 5000000)
log.addHandler(dh)
The logger handler is defined as follows:
class RotatingSqliteHandler(logging.Handler):
def __init__(self, filename, progData, maxBytes=0):
logging.Handler.__init__(self)
self.user = progData['user']
self.host = progData['host']
self.progName = progData['name']
self.site = progData['site']
self.pid = random.getrandbits(50)
.....
in the log I see that process ID which logger generates in the last line is the same for the both scripts.
I'll try to use logger name unique to each script run instead of 'MyLog'. Although it is strange that a logger instance can be got from another process.