WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 11-02-2005, 03:35 PM
Vygreif Vygreif is offline
Member
 
Join Date: Sep 2005
Posts: 21
Sending Objects With Pickle

Hi,
I want to send an object over the network. The object contains other variables which can't be pickled (it gives the error can't pickle webCam objects). Is there any way to pickle only part of the object (I don't care to send over the webcam object). Or another way to send my object over the network?

Thanks,
YG
Reply With Quote
  #2  
Old 11-02-2005, 05:08 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

Is this object a class instance that you created? If it is then you need to override the __getstate__ and __setstate__ functions in order to bypass pickling of the webCam object. Here is an example:
Code:
class MyClass:
    def __init__(self):
        self.webCam = 0
        self.variable = 'something'

    def __getstate__(self):
        odict = self.__dict__.copy() # copy the dict since we change it
        del odict['webCam']          # remove webCam variable
        return odict

    def __setstate__(self,dict):
        self.webCam = 0              # initialize webCam object since it won't be in dict
        self.__dict__.update(dict)   # update attributes
Reply With Quote
  #3  
Old 11-02-2005, 07:47 PM
Vygreif Vygreif is offline
Member
 
Join Date: Sep 2005
Posts: 21
Hi,
I'm trying to use your method. But I think I can't get it to override

def __getState__(self):

I tried the following code

def __getState__(self):
assert 0 == 1, 'Overriden'
print 5/0
odict = self.__dict__.copy()
del odict['NodShakeDetector']
del odict['LookAwayDetector']
del odict['TalkingDetector']
return odict

def __setstate__(self, dict):
#self.webCam = 0 # initialize webCam object since it won't be in dict
self.__dict__.update(dict) # update attributes

But I don't think it ever calls getState, I neither get a divide by 0 error, nor an assert. And if I don't have the assert or the divide by 0 error it complains about the pickle error.
Reply With Quote
  #4  
Old 11-02-2005, 07:49 PM
Vygreif Vygreif is offline
Member
 
Join Date: Sep 2005
Posts: 21
Heh, sorry, my bad for capitilizing getState
Reply With Quote
  #5  
Old 11-02-2005, 08:22 PM
Vygreif Vygreif is offline
Member
 
Join Date: Sep 2005
Posts: 21
But . . . one more question.
I have

s = pickle.dumps(localStats)
t = pickle.dumps(localData)
network.send(s,t)

And as far as I can tell nothing gets sent, I never recieve anything with that code.

And I'm pretty sure the pickiling works because when I print s, t
I get a long string back.
I also tested network.send for integers (eg network.send(5)), and that sends fine.
Is there a limit to the size of the file that network.send can take? Or can you think of another reason why the program is failing?

Thanks,
YG
Reply With Quote
  #6  
Old 11-03-2005, 09:17 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

There is an internal limit in Vizard on how big a message it can receive over the network. Currently the size is 4096 bytes. The pickle string is probably exceeding this size.

This is an unusually large size to be sending over the network. Are you sending these messages every frame? If possible, try to cut down the size of the message to only the relevant data. If you still need to send this much data then let me know and I will provide you with a work around.
Reply With Quote
  #7  
Old 11-05-2005, 02:42 PM
Vygreif Vygreif is offline
Member
 
Join Date: Sep 2005
Posts: 21
Hi,
It was too large of a file size, but I found an alternate solution to the problem, thanks though.
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 07:41 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC