<div dir="ltr">Hi Allan, <div><br></div><div>apologies for resurrecting this very old thread, but I'm kind of stuck again. </div><div><br></div><div>In short, I'm developing a bundle for sending messages to the Extempore compiler (<a href="http://extempore.moso.com.au/">http://extempore.moso.com.au/</a>; <a href="http://benswift.me/2012/09/26/interacting-with-the-extempore-compiler/">http://benswift.me/2012/09/26/interacting-with-the-extempore-compiler/</a>) which should happen via a TCP socket connection. </div><div><br></div><div>Ideally, I'd like to create the following commands:</div><div><br></div><div>a) start the server [done, see <a href="https://github.com/lambdamusic/extempore-bundle">https://github.com/lambdamusic/extempore-bundle</a>]</div><div>b) set up a reusable socket connection object </div><div>c) evaluate expressions by sending them to the server using the connection object </div><div><br></div><div>I've set up environment variables in Textmate to hold my connection settings; also, I've created a variable called EXTEMPORE_CONNECTION which in theory should keep the pickled version of my server socket. </div><div><br></div><div>Here's my Python command:</div><div><br></div><div>>>>>>><br></div><div><div>#!/usr/bin/env python</div><div># -*- coding: utf-8 -*-</div><div><br></div><div>import os, socket</div><div>import pickle</div><div><br></div><div>xtm_host = str(os.environ.get('EXTEMPORE_HOST', "127.0.0.1"))<br></div><div>xtm_port = int(os.environ.get('EXTEMPORE_PORT', 7099)) </div><div><br></div><div>sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)</div><div><br></div><div>HOST = xtm_host </div><div>PORT = xtm_port</div><div><br></div><div>sock.connect((HOST, PORT))</div><div>data = sock.recv(1024)</div><div>print(data) # welcome message, works.</div><div><br></div><div>os.environ['EXTEMPORE_CONNECTION'] = pickle.dumps(sock, -1) # *fails*</div><div><br></div></div><div>>>>>>>></div><div><br></div><div>The problem is, Python's pickle doesn't support all kinds of objects, and sockets are among those (see <a href="http://stackoverflow.com/questions/2204155/why-am-i-getting-an-error-about-my-class-defining-slots-when-trying-to-pickl">http://stackoverflow.com/questions/2204155/why-am-i-getting-an-error-about-my-class-defining-slots-when-trying-to-pickl</a>)</div><div><br></div><div>So I wonder if there's another way of approaching the problem; or, if by any chance, the same approach done via another language (eg Ruby) would not encounter any limitation.. </div><div><br></div><div>Thanks in advance for the help, </div><div><br></div><div>Michele</div><div> </div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><br></div><div><br></div><div><br></div><div><br></div><div><font size="1" face="courier new, monospace" style="background-color:rgb(255,255,255)" color="#cccccc">--------</font></div><div><font size="1" face="courier new, monospace" style="background-color:rgb(255,255,255)" color="#cccccc">Michele Pasin</font></div><div><font size="1" face="courier new, monospace" style="background-color:rgb(255,255,255)"><font color="#cccccc">Email: </font><a href="mailto:michele.pasin@gmail.com" target="_blank"><font color="#999999">michele.pasin@gmail.com</font></a></font></div><div><font size="1" face="courier new, monospace" style="color:rgb(204,204,204);background-color:rgb(255,255,255)">Web: </font><a href="http://www.michelepasin.org" style="font-family:'courier new',monospace;font-size:x-small" target="_blank"><font color="#999999">www.michelepasin.org</font></a></div><div><span style="font-family:'courier new',monospace;font-size:x-small"><font color="#cccccc">--------</font></span><br></div></div></div></div></div></div>
<br><div class="gmail_quote">On 14 August 2013 at 09:55, Allan Odgaard <span dir="ltr"><<a href="mailto:mailinglist@textmate.org" target="_blank">mailinglist@textmate.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 14 Aug 2013, at 2:41, Michele Pasin wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
[…] when I do this<br>
os.environ['TM_PROJECT_UUID'] = someobject<br>
I get an error […]<br>
</blockquote>
<br>
You can’t assign to environment variables. The variable is to be used as a key into a database, in the simplest case something like:<br>
<br>
uuid = os.environ['TM_PROJECT_UUID'] # Same when window is the same<br>
file = os.path.join(tempfile.gettempdir(), "tm_«your_command»_" + uuid + ".pickle")<br>
pickle.dump(someobject, file)<br>
<br>
For each invocation of your command, ‘uuid’ will be the same, as long as it’s called for the same (project) window.<br>
<br>
Your command would start by testing if ‘file’ already exists, and if so, read ‘someobj’ by unpickling it.<div class="HOEnZb"><div class="h5"><br>
<br>
_______________________________________________<br>
textmate mailing list<br>
<a href="mailto:textmate@lists.macromates.com" target="_blank">textmate@lists.macromates.com</a><br>
<a href="http://lists.macromates.com/listinfo/textmate" rel="noreferrer" target="_blank">http://lists.macromates.com/listinfo/textmate</a></div></div></blockquote></div><br></div>