def dispy_send_file(path, timeout=MsgTimeout):
    """Computations may use this function to send files back to the client.

    If the computations have small amount of data to be sent back to
    the client, then the return value can be used for that
    purpose. However, if (temporary) result is stored in file(s), then
    those file(s) can be sent back to the client.

    File at given 'path' is sent to the client, which saves the file
    with the same path under its working directory. If multiple jobs
    on different nodes send files, care must be taken to use different
    paths so files sent by one job don't overwrite files sent by other
    jobs.

    If file size exceeds 'MaxFileSize' bytes, this function returns -1,
    without sending it.

    'timeout' is seconds for socket connection/messages; i.e., if
    there is no I/O on socket (to client), this call fails. Default
    value for it is MsgTimeout (5) seconds.

    Return value of 0 indicates successfull transfer.
    """

    path = os.path.expanduser(path)
    xf = _XferFile(path, os.stat(path))
    if MaxFileSize and xf.stat_buf.st_size > MaxFileSize:
        return -1
    xf.name = os.path.splitdrive(path)[1]
    if xf.name.startswith(os.sep):
        xf.name = xf.name[len(os.sep):]
    dispy_job_reply = __dispy_job_info.job_reply
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock = AsyncSocket(sock, blocking=True,
                       keyfile=__dispy_job_keyfile, certfile=__dispy_job_certfile)
    sock.settimeout(timeout)
    try:
        sock.connect(__dispy_job_info.reply_addr)
        sock.send_msg('FILEXFER:'.encode() + serialize(xf))
        sock.send_msg(serialize(dispy_job_reply))
        recvd = sock.recv_msg()
        recvd = unserialize(recvd)
        fd = open(path, 'rb')
        sent = 0
        while sent == recvd:
            data = fd.read(1024000)
            if not data:
                break
            sock.sendall(data)
            sent += len(data)
            recvd = sock.recv_msg()
            recvd = unserialize(recvd)
        fd.close()
        assert recvd == xf.stat_buf.st_size
    except:
        print('Could not transfer file "%s": %s' % (path, traceback.format_exc()))
        return -1
    else:
        return 0
    finally:
        sock.close()
dataset/ETHPy150Open pgiri/dispy/py2/dispy/dispynode.py/dispy_send_file/original