pexpect problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • flynnguy@gmail.com

    #1

    pexpect problems

    I am trying to essentially fork a rsync process from my python script
    and I am having some issues with the forking part. My program basically
    checks to see if I need to transfer a file and if it does, it calls the
    transferItem() function below:

    def transferItem(fi lelist):
    hostname, passwd, transdir, filepath = filelist
    command = "nice -n +19 %s --partial --bwlimit=\"%d\" \"%s\" %s:%s"
    % (COMMAND_TO_CHE CK, BANDWIDTH_LIMIT , filepath, hostname, transdir)
    p = pexpect.spawn(c ommand)
    try:
    ret = p.expect(["(yes/no)", "Password:"])
    if ret == 0:
    p.sendline("yes ")
    p.expect("Passw ord:")
    p.sendline(pass wd)
    p.expect(pexpec t.EOF, timeout=999)
    except:
    print 'problem transferring file'

    Now this seems to partially work (it transfers the file) but I have a
    few issues I'm hoping someone can help me with. First there is the
    timeout issue. Without the timeout=999 parameter, the default timeout
    is 30 seconds. I'd rather not have any timeout because the files I need
    to transfer can be quite large and may take several days in some cases.
    I tried p.close(wait=Fa lse) but that creates a defunct process and
    doesn't seem to transfer any of the file. I can also say p.interact()
    which won't timeout on me but it also doesn't fork into the background.


    I thought the best solution would be to use the p.interact() and fork
    the process but I can't seem to get that working. Anyone have any ideas
    or suggestions that might help me?

    Also just as a background in case it helps, I am currently writing a
    pickled object (List of list) to a file using a web frontend (using
    django) and then I have a monitor script which first checks if it
    should transfer a file (based on how many transfers are currently
    running) and then opens the pickled object and pop's off the first item
    and sends that as input to the above function which I'm hoping will
    start the rsync and then keep on chugging. I'd really appreciate any
    help anyone could offer.
    -Chris

Working...