473,326 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

PS: Help pickling across sockets

Just after posting the previous request, I realised that my test case
worked after I added flushes. The next problem I have is that, in the
real program, the server gets an EOFError when it first tries to read
from the socket. Relevant portions follow the error message below:

Traceback (most recent call last):
File "/var/www/cgi-bin/datamine", line 1633, in ?
find_and_output_appropriate_page()
File "/var/www/cgi-bin/datamine", line 1461, in
find_and_output_appropriate_page
sys.stdout.write(get_output())
File "/var/www/cgi-bin/datamine", line 1497, in get_output
return multitasking.get_page_from_oracle()
File "/var/www/cgi-bin/datamine", line 976, in get_page_from_oracle
self.check_and_start_oracle()
File "/var/www/cgi-bin/datamine", line 972, in check_and_start_oracle
self.start_oracle()
File "/var/www/cgi-bin/datamine", line 1083, in start_oracle
self.run_oracle()
File "/var/www/cgi-bin/datamine", line 1056, in run_oracle
self.handle_oracle_query(newsocket, address)
File "/var/www/cgi-bin/datamine", line 1015, in handle_oracle_query
self.get_thread_specific_storage()["environment_variables"] = \
EOFError
Traceback (most recent call last):
File "/var/www/cgi-bin/datamine", line 1633, in ?
find_and_output_appropriate_page()
File "/var/www/cgi-bin/datamine", line 1461, in
find_and_output_appropriate_page
sys.stdout.write(get_output())
File "/var/www/cgi-bin/datamine", line 1497, in get_output
return multitasking.get_page_from_oracle()
File "/var/www/cgi-bin/datamine", line 988, in get_page_from_oracle
result = cPickle.load(sockIn)
IOError: [Errno 104] Connection reset by peer

From the server side, here are run_oracle() and handle_oracle_query():

def run_oracle(self):
#thread.start_new_thread(\
#self.initialize, ())
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(("", configuration.get_search_server_port()))
sock.listen(5)
while 1:
try:
newsocket, address = sock.accept()
self.handle_oracle_query(newsocket, address)
#thread.start_new_thread(self.handle_oracle_query,
(newsocket, \ #address))
except socket.error:
sock.close()
sock = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,
1)
sock.bind(("", configuration.get_search_server_port()))
sock.listen(5)

def handle_oracle_query(self, sock, address):
sockIn = sock.makefile("rb")
sockOut = sock.makefile("wb")
sockIn.flush()
### Line 1015, immediately below, is where the EOF error is reported.
self.get_thread_specific_storage()["environment_variables"] = \
cPickle.load(sockIn)
sockIn.flush()
self.get_thread_specific_storage()["cgi"] =
cPickle.load(sockIn)
generate_output()
print_output(sockOut)
sockOut.flush()
sock.close()
sockIn.close()
sockOut.close()

From the client side, here is get_page_from_oracle():

def get_page_from_oracle(self):
self.check_and_start_oracle()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.connect((configuration.get_search_server_ip() , \
configuration.get_search_server_port()))
sockIn = sock.makefile("rb")
sockOut = sock.makefile("wb")
cPickle.dump(os.environ, sockOut)
sockOut.flush()
cPickle.dump(cgi.FieldStorage(), sockOut)
sockOut.flush()
sockIn.flush()
### Line 988, immediately below, also gets an error, but I believe
this is secondary damage.
result = cPickle.load(sockIn)
sock.close()
sockIn.close()
sockOut.close()
return result

TIA,
++ Jonathan Hayward, jo**************@pobox.com
** To see an award-winning website with stories, essays, artwork,
** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at http://JonathansCorner.com
Jul 18 '05 #1
1 2468
Jonathan Hayward wrote:
Just after posting the previous request, I realised that my test case
worked after I added flushes. The next problem I have is that, in the
real program, the server gets an EOFError when it first tries to read
from the socket.


I'm not sure, but perhaps pickle doesn't work on sockets directly?
Perhaps it needs a random-access file object.

So, read all the data from the socket yourself, into a string
buffer, and run pickle on that.

That's what I do in Pyro :-)

HTH,
--Irmen de Jong

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: gong | last post by:
hi i would like to pickle a lambda; according to the library docs in 2.3, i believe this shouldnt be possible, since a lambda is not a function defined at the top level of a module (?) ...
1
by: Marc | last post by:
Hi all, After some research I've decided that my previous question (Confusing problem between Tkinter.Intvar...) was headed in the wrong direction. Partly because I think I have a greater...
1
by: Edward Loper | last post by:
I'm having trouble pickling subclasses of dict when they contain cycles. In particular: >>> import pickle >>> class D(dict): pass >>> d = D() >>> d = d # add a cycle. >>> print d {1: {...}}...
8
by: Hans Georg Krauthaeuser | last post by:
Dear all, I have a long running application (electromagnetic compatibility measurements in mode-stirred chambers over GPIB) that use pickle (cPickle) to autosave a class instance with all the...
1
by: fedor | last post by:
Hi all, happy new year, I was trying to pickle a instance of a subclass of a tuple when I ran into a problem. Pickling doesn't work with HIGHEST_PROTOCOL. How should I rewrite my class so I can...
1
by: Erik Max Francis | last post by:
I've come across a limitation in unpickling certain types of complex data structures which involve instances that override __hash__, and was wondering if it was known (basic searches didn't seem to...
0
by: Irmen de Jong | last post by:
I'm having troubles pickling classes that extend Exception. Given the following source: class Foo(object): def __init__(self, m): self.m=m class Bar(Exception): def __init__(self, m):
3
by: itcoll | last post by:
i have wriiten java code for client server communication - the client sends a digital signature and the server verifies it using the public key .I have sent the signature as a string from the client...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.