• Barry Warsaw's avatar
    Rework the background threads to be poll-with-timeout based instead of · 6e8fbfb4
    Barry Warsaw authored
    sleep based.  We create two ends of a pipe in the parent thread, with
    the child thread polling/reading one end and the parent writing to the
    other.  The only thing written to this pipe is a "stop marker" -- just
    a string that wakes the thread up immediately when we're closing the
    storage.
    
    The primary reason for this is to speed up shutdown so that we don't
    have to wait for the next tick of the sleep counter before we'll
    trigger the thread shutdown.  Makes shutting down Zope using this
    storage much quicker.
    
    Specific changes include:
    
    BerkeleyBase.py
    
        SLEEP_TIME -> JOIN_TIME since it's now just the interval we'll
        wait for the thread.join to complete.
    
        __init__():	Create both the checkpointer thread and the autopacker
        thread, set up the pipes, and get them both rolling.  We refactor
        creation of the autopacker instance into a separate overrideable
        method since this is the one bit that's different between the two
        storages.
    
        _make_autopacker(): Intended to be overridden.
    
        close(), _doclose(): Move the thread shutdown code out of the
        lock, since we don't want to potentially deadlock the shutting
        down of the background thread.  This could happen if close() was
        entered when the autopacker thread was between lock acquisitions
        in _dopack().  Also, be sure to write to the pipe to wake the
        child threads up immediately.
    
        env_from_string(): Wrap the actual creation and opening of the
        environment in a try/except, so that if there's a failure, we can
        be sure to give up the file lock.
    
        _WorkThread class: Accept a poll object which wraps the read end
        of the pipe.  Rework run() to do the poll-with-timeout instead of
        sleep.  I don't think we strictly need to do the fd read given the
        simplicity (and mono-commandity) of the protocol, but it can't
        hurt.  The _dowork() method's signature no longer contains the
        `now' variable.
    
    Full.py
    
        _make_autopacker(): Override base class to return storage specific
        _Autopack instance.
    
    Minimal.py
    
        Same, but also include some code cleanup.
    
    
    Also, get rid of some unnecessary imports.
    6e8fbfb4
Minimal.py 21.7 KB