Sharing common memory space (In form of List) across the python processes.

2008-08-26 Thread Piyush Chechani
Hi,

Thanks for your reply Terry.

I am still not done with this problem. Please tell me can a server send a 
list object using socket programming to the requesting client?
If yes, how? I am getting the following error 
TypeError: send() argument 1 must be string or read-only buffer, 
not list

For sending list object I tried the following code: - 

Server Code: -
-
someList = [ 1, 2, 7, 9, 0 ]
pickledList = pickle.dumps ( id(someList) )

# Our thread class:
class ClientThread ( threading.Thread ):

# Override Thread's __init__ method to accept the parameters needed:
   def __init__ ( self, channel, details ):

  self.channel = channel
  self.details = details
  threading.Thread.__init__ ( self )

   def run ( self ):

  print 'Received connection:', self.details [ 0 ]
  self.channel.send ( pickledList )
 
  self.channel.close()
  print 'Closed connection:', self.details [ 0 ]

# Set up the server:
server = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
server.bind ( ( '', 2727 ) )
server.listen ( 5 )

# Have the server serve forever:
while True:
channel, details = server.accept()
print channel, details
ClientThread ( channel, details ).start()


Client Code: -
-
class ConnectionThread ( threading.Thread ):

   def run ( self ):

  # Connect to the server:
  client = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
  client.connect ( ( 'localhost', 2727 ) )
  #print 'Connected!!',client

  # Retrieve and unpickle the list object:
  lst= pickle.loads ( client.recv ( 1024 ) )

  # Close the connection
  client.close()

# Let's spawn a few threads:
for x in xrange ( 10 ):
   ConnectionThread().start()
-

In the above code I am able to get the id of the server List in the 
client, but can not access the content at the client. And if I send the 
pickled list to the client, it creates a new list at the client end, which 
is not desirable.

Please suggest how to share a in-memory list object across two different 
programs?

Thanks.
Piyush.
=-=-=
Notice: The information contained in this e-mail
message and/or attachments to it may contain 
confidential or privileged information. If you are 
not the intended recipient, any dissemination, use, 
review, distribution, printing or copying of the 
information contained in this e-mail message 
and/or attachments to it are strictly prohibited. If 
you have received this communication in error, 
please notify us by reply e-mail or telephone and 
immediately and permanently delete the message 
and any attachments. Thank you


--
http://mail.python.org/mailman/listinfo/python-list

Re: Sharing common memory space (In form of List) across the python processes.

2008-08-26 Thread D'Arcy J.M. Cain
On Tue, 26 Aug 2008 18:18:53 +0530
Piyush Chechani [EMAIL PROTECTED] wrote:
 Please suggest how to share a in-memory list object across two different 
 programs?

Perhaps you want to investigate XML-RPC.  Check the docs for some
example scripts for both client and server.

P.S. Please drop the legal crap from your postings.  This is a public
list and such things are just a waste of space.

-- 
D'Arcy J.M. Cain [EMAIL PROTECTED] |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Sharing common memory space (In form of List) across the python processes.

2008-08-01 Thread Terry Reedy



Piyush Chechani wrote:


Hi,

I am working on a module where I need to share contents of a big List 
across the processes. I am using socket programming concept for this.


My current processing for this is as follows: -
1. There is a server program S which loads the list in the 
memory, and listens on a particular port,
2. All the other programs which want to access that list sends a 
request on that server port,
3. Server sends the id of the memory loaded list element to the 
requesting process.
Here I am getting a problem in the reverse function of id(), as my 
client should get the list object using its id but I don't know the 
python function for doing this.


There intentionally is no such function.  If by 'process', I believe you 
should just send the object, which actually just sends an internal 
reference to the object.  If you mean OS process, look into interprocess 
communication.  3.0 has a new multiprocessing module that might help. 
Or have your server perform manipulations on the object.


--
http://mail.python.org/mailman/listinfo/python-list