server bootstrapping upon connection (WARNING: LONG)

Benjamin Han this at is.for.spambot
Wed Feb 11 11:49:19 EST 2004


On 2004-02-10 19:59:47 -0500, Benjamin Han <this at is.for.spambot> said:

> On 2004-02-10 18:22:30 -0500, ralf at brainbot.com said:
> 
>> Benjamin Han <this at is.for.spambot> writes:
>> 
>>> On 2004-02-10 13:46:37 -0500, ralf at brainbot.com said:
>>> 
>>>> fortepianissimo at yahoo.com.tw (Fortepianissimo) writes:
>>>>> The problem: I need to prevent multiple copies of the server being
>>>>> started. I did this by using file locking (fcntl.lockf()). However,
>>>>> not every time the code successfully prevented the server being
>>>>> started up more than one time. Here is the relevant code:
>>>> ...  from the "ps" log during the stress test, I still get two servers 
>>>> started up, listed by ps like this:
> 
> 27308  ??  S      0:01.25 python -OO fooServer.py
> 27465  ??  SV     0:01.25 python -OO fooServer.py
> 
> In this case the one with pid 27308 was the first server process 
> started. Some time later, with unknown reason, another server entry 
> will show up in ps log, but the status is always "RV" or "SV" (e.g., 
> pid 27465). The way I started the server in the code is os.system() 
> call, and from the man page of ps, 'V' means "The process is suspended 
> during a vfork."
> 
> The weird thing is I also have log statements in the server script, and 
> from the log file only ONE copy is actually started. I start to suspect 
> that I might have misunderstood the ps log - could it be there really 
> is only ONE copy running, despite there're (up to) 2 entries shown in 
> the ps log?

Ok this is by far the most puzzling one: I use logger module in the 
server script to notify its execution. The code is like this:

--- LOGGING CODE STARTS ---
if FOO_COMM_DEBUG:
    myPID=os.getpid()
    logger = logging.getLogger('FOO Comm')
    hdlr = logging.FileHandler(TMP_PATH+'fooComm.log')
    formatter = logging.Formatter('%(asctime)s %(message)s')
    hdlr.setFormatter(formatter)
    logger.addHandler(hdlr) 
    logger.setLevel(logging.INFO)

    def log (info):
        logger.info('Server %d: %s'%(myPID,info))

if FOO_COMM_DEBUG: log('process %d started me'%os.getppid())
--- LOGGING CODE ENDS ---

This is the FIRST block of code right after my "import ..." statement 
in the server script, so there's no way that it could be skipped if the 
script gets executed. Of course FOO_COMM_DEBUG is set to 1.

But as described, the ps log showed two entries of fooServer.py, but in 
the log produced, only one server actually was started (I can tell that 
from the PID in the log file). I really can't explain this discrepency!




More information about the Python-list mailing list