简体   繁体   中英

How can you serialize dynamic class instances in Python?

I have a wsdl that takes more than two minutes to parse with Suds. This is too long because I want to use a client object in a short lived process. I'd like to persist the client object as a static resource to avoid the overhead of creating a client each time. A few people have suggested a sort of singleton pattern to store the client object in a running process, but I want a short lived process. I'm also not looking for an explanation about why pickling dynamically created classes doesn't work, so only post if you have a solution.

from suds.client import Client

url = 'http://mssoapinterop.org/asmx/simple.asmx?WSDL'
client = Client(url)
print client

Since pickling won't work, is there some way to grab the exact bytes for the client object out of memory using the address location, store it as a binary blob, and then load them back into memory later? Maybe using ctypes ?

Are you asking a question that is specific to the suds library. It would be helpful if you can abstract the question to a generic python question not related to a particular library.

Assuming you are only interested in the data in the output of the client call which contains values returns from an HTTP call.... why not translate the returned data into your own class format that is not dynamic and then serialize / pickle that.

If you are trying to serialize the state of some TCP connection that seems awkard anyway.

Perhaps you can clarify.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM