开发者

Watch over another process (svn)

I have a python script to download source code from a list of repositories, some of them are big.

Sometimes, svn hangs in the middle of a check out. Is there a way to watch over svn process, and 开发者_StackOverflow中文版so I know it is hang or not?


You can use PySVN, and register a callback for each "event" processes. PySVN can also poll a "cancel" callback. The first callback could start a timer, and if the timer expires, you can do tell the "cancel" callback to return False, thus cancelling the checkout.

#!/usr/bin/python

url = "svn://server/path/to/repo"
path = "/path/to/local/wc"

import pysvn
import threading

# Set to something reasonable
SVN_TIMEOUT = 1000

svn_timer = None
stop_svn = False

def timer_expired():
    # Too long since last SVN event, so do something sensible...
    print "SVN took too long!"
    global stop_svn
    stop_svn = True

def svn_cancel():
    return stop_svn

def notify( event_dict ):
    global svn_timer
    if svn_timer:
        svn_timer.cancel()
    svn_timer = threading.Timer(SVN_TIMEOUT, timer_expired)
    svn_timer.start()

svn_client = pysvn.Client()
svn_client.callback_notify = notify
svn_client.callback_cancel = svn_cancel

svn_timer = threading.Timer(SVN_TIMEOUT, timer_expired)
svn_timer.start()

revision = svn_client.checkout(url,path)

if svn_timer:
    svn_timer.cancel()


You can keep polling the stdout of the svn process, and test how often you get new files. If you don't get a new file within x seconds, bounce the process.

Launch svn using subprocess from within your master script, and poll stdout while waiting for the process to complete.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜