Just learned about rpyc last week, very impressive, lots of promise.

if I could just learn to to make it do what I wanted on my Mac

Right now I having trouble with copying files, using Mac OS X Mavericks, in 
case that matters.  

Experiment #1 --- use classic mode, follow instructions to import rpyc and 
make a connection.
The very same unhappiness below happens with different python 
implementations (2.7 and 3.4.1)

dmnicol-MacBook-Pro-5:dmnicol$ python3
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 00:54:21) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import rpyc
>>> conn = rpyc.classic.connect('localhost')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File 
"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/rpyc/utils/classic.py",
 
line 68, in connect
    return factory.connect(host, port, SlaveService, ipv6 = ipv6, keepalive 
= keepalive)
  File 
"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/rpyc/utils/factory.py",
 
line 89, in connect
    s = SocketStream.connect(host, port, ipv6 = ipv6, keepalive = keepalive)
  File 
"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/rpyc/core/stream.py",
 
line 132, in connect
    return cls(cls._connect(host, port, **kwargs))
  File 
"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/rpyc/core/stream.py",
 
line 102, in _connect
    s.connect(sockaddr)

ConnectionRefusedError: [Errno 61] Connection refused

-----------
well, huh.

I actually started first with service oriented mode, and looked at classic 
mode only when
I couldn't get service oriented stuff to work.

Here's the server code
------- fileServer.py ------
import rpyc
import sys
import argparse
from rpyc.utils.server import ThreadedServer

# this code comes straight off a 'this works for me' example
class FileService(rpyc.Service):
    def exposed_open(self,filePath, mode = 'r'):
        return open(filePath,mode)

# argparse is overkill for this, but I'm a fan
parser = argparse.ArgumentParser()
parser.add_argument(u'-port',  metavar = u'use this port', dest= u'port', 
required=True)
args = parser.parse_args( sys.argv[1:] )

if __name__ == "__main__":
    # just like numerious examples on the web
    t = ThreadedServer(FileService, port=int(args.port))
    t.start()

--------------
now the client code

------- fileClient.py -------

from __future__ import print_function
import rpyc
import argparse
import os
import sys
import shutil

# after this args.directory holds directory path and args.port the port 
number of the server
parser = argparse.ArgumentParser()
parser.add_argument(u'-port',  metavar = u'use this port', dest= u'port', 
required=True)
parser.add_argument(u'-dir',  metavar = u'local directory name', dest= 
u'directory', required=True)
args = parser.parse_args( sys.argv[1:] )

# proof that the problem is not junk coming in from the command line
if not os.path.isdir(args.directory):
    print ('directory', args.directory,'not accessible')
    exit (1)

# use os.path.join to show problem is not due to badly formated path name
localPath     = os.path.join(args.directory,'destination.txt')
remotePath    = os.path.join(args.directory,'source.txt')

# test each line separately to isolate the failure
try:
localFile     = open(localPath, 'w')
except:
        print('cannot open',localPath)
        exit
try:
    conn          = rpyc.connect('localhost', port = int(args.port))
except:
    print('rpyc.connect failed')
    exit
try:
remoteFile    = conn.root.open( remotePath, 'r' )
except:
print('conn.root.open failed')
exit

try:
    shutil.copyfileobj(remoteFile, localFile)
except:
    print ('copyfileobj error:', sys.exc_info()[0])

---------------
so let's take it out for a spin

-----------
dmnicol-MacBook-Pro-5:np-live dmnicol$ 
dmnicol-MacBook-Pro-5:np-live dmnicol$ ls testing/
source.txt
dmnicol-MacBook-Pro-5:np-live dmnicol$ python3 fileServer.py -port 11111 &
[1] 24764
dmnicol-MacBook-Pro-5:np-live dmnicol$ python3 fileClient.py -port 11111 
-dir 'testing'
copyfileobj error: <class 'AttributeError'>

-----------
and what attribute error might that be?  Bring in pdb, step to the 
offending line and see

-> shutil.copyfileobj(remoteFile, localFile)

(Pdb) shutil.copyfileobj(remoteFile, localFile)

*** AttributeError: cannot access 'read'

========= Remote Traceback (1) =========
Traceback (most recent call last):
  File 
"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/rpyc/core/protocol.py",
 
line 305, in _dispatch_request
    res = self._HANDLERS[handler](self, *args)
  File 
"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/rpyc/core/protocol.py",
 
line 541, in _handle_getattr
    return self._access_attr(oid, name, (), "_rpyc_getattr", 
"allow_getattr", getattr)
  File 
"/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/rpyc/core/protocol.py",
 
line 504, in _access_attr
    raise AttributeError("cannot access %r" % (name,))
AttributeError: cannot access 'read'

------------------------
I'm not so sophomoric to believe I'm not doing something wrong here, but 
the code is taken nearly
exactly as I'm finding examples to follow.   Any help will be appreciated.


You received this message because you are subscribed to the Google Groups 
>> "rpyc" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"rpyc" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to