Return a string result with out breaking loop

Andrew nobody at yahoo.com
Tue Aug 26 04:14:39 CEST 2008


I run the server then execute the client. From the client I execute the 
function key.watchos()

My goal is an administration tool

and this is just a function in my goal :-)



Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Maboroshi>python C:\software\mabssystem\client.py
Use the keyword, "key" to interact with the server
 >>> key.watchos()
Traceback (most recent call last):
   File "<console>", line 1, in <module>
   File "C:\Python25\lib\xmlrpclib.py", line 1147, in __call__
     return self.__send(self.__name, args)
   File "C:\Python25\lib\xmlrpclib.py", line 1437, in __request
     verbose=self.__verbose
   File "C:\Python25\lib\xmlrpclib.py", line 1201, in request
     return self._parse_response(h.getfile(), sock)
   File "C:\Python25\lib\xmlrpclib.py", line 1340, in _parse_response
     return u.close()
   File "C:\Python25\lib\xmlrpclib.py", line 787, in close
     raise Fault(**self._stack[0])
Fault: <Fault 1: "<type 'exceptions.TypeError'>:cannot marshal <type 
'generator'
 > objects">
 >>>

the function watchos is basically based off of Tim Goldens Directory 
watching app

the function is as follows in entirety

     def watchos(self, path_to_watch="C:\\"):
         #get path or maintain current path of app
         FILE_LIST_DIRECTORY = 0x0001
         try: path_to_watch or "."
         except: path_to_watch = "."
         path_to_watch = os.path.abspath(path_to_watch)

         out1 = "Watching %s at %s" % (path_to_watch, time.asctime()) + 
"\n\n"
         # FindFirstChangeNotification sets up a handle for watching
         #  file changes.
         while 1:

             hDir = win32file.CreateFile (
                 path_to_watch,
                 FILE_LIST_DIRECTORY,
                 win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE,
                 None,
                 win32con.OPEN_EXISTING,
                 win32con.FILE_FLAG_BACKUP_SEMANTICS,
                 None
                 )

             change_handle = win32file.ReadDirectoryChangesW (
                 hDir,
                 1024,
                 True,#Heap Size include_subdirectories,
                 win32con.FILE_NOTIFY_CHANGE_FILE_NAME |
                 win32con.FILE_NOTIFY_CHANGE_DIR_NAME |
                 win32con.FILE_NOTIFY_CHANGE_ATTRIBUTES |
                 win32con.FILE_NOTIFY_CHANGE_SIZE |
                 win32con.FILE_NOTIFY_CHANGE_LAST_WRITE |
                 win32con.FILE_NOTIFY_CHANGE_SECURITY,
                 None,
                 None
                 )

             # Loop forever, listing any file changes. The WaitFor... will
             #  time out every half a second allowing for keyboard 
interrupts
             #  to terminate the loop.
             ACTIONS = {
                 1 : "Created",
                 2 : "Deleted",
                 3 : "Updated",
                 4 : "Renamed from something",
                 5 : "Renamed to something"
                 }

             results = change_handle
             for action, files in results:
                 full_filename = os.path.join(path_to_watch, files)
                 theact = ACTIONS.get(action, "Unknown")
                 yield str(full_filename) +  " " + str(theact)


and the rpc client is as follows

import xmlrpclib, code

# Specify IP of Server here defualt port is 9000
url = "http://127.0.0.1:8888"
sock = xmlrpclib.ServerProxy(url, allow_none=True, verbose=0)
# use the interactive console to interact example "key.keyit()" will 
start the logger
interp = code.InteractiveConsole({'key': sock})
interp.interact("Use the keyword, \"key\" to interact with the server")

Sorry if I posted to much code :-)

Thank you in advance



More information about the Python-list mailing list