[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: restarting processes when python libraries are upgraded?



On 20/06/11 04:51, Paul Wise wrote:
> […] which servers to restart when upgrading a
> python library for security updates. Any thoughts?


Your Python process knows what it's got imported by looking as
sys.modules. Could your trigger prod it with some signal to tell it to
dump filenames to some well-known location? It could then check that
list for updated files.

Something like:

"""
import os
import signal
import sys
import time

def dump_modules(signum, frame):
    filenames = [m.__file__ for m in sys.modules.itervalues() if
hasattr(m, '__file__')]
    with open('module_filenames.txt', 'w') as f:
        for filename in filenames:
            filename = os.path.abspath(filename)
            f.write(filename + '\n')

signal.signal(signal.SIGUSR1, dump_modules)

while True:
    time.sleep(1)
"""


Yours,

Alex

[NB: I know very little about the Debian/packaging-side of things. I
hope to rectify this soon!]


Reply to: