how to communicate in python with an external process
Howdy, I'm a long time python user but ran across something I have never needed to do before and don't know how to do it. The issue is that I need for my python script to call some matlab routines. Matlab is very expensive to start running, so I only want to run it once. I also want the changes I make in one call to matlab persist to the next call to matlab. I don't know how to do this. What I want to do is something like create a matlab process, get it's pid and then attach later (this can be in blocking mode) to that pid to execute the command, read the output, then go on in my python code and at some point later, repeat the process of attaching to the persistent matlab pid... I am familiar with subprocess.Popen, but I don't understand how to attach to a pid, as opposed to creating a new matlab instance every time. Any enlightenment would be appreciated. thanks, Danny -- http://mail.python.org/mailman/listinfo/python-list
Re: how to communicate in python with an external process
>
> http://pypi.python.org/pypi/pymatlab/
>
> Cheers,
> Chris
I am on a mac. Does pymatlab support mac's? I tried the linux 64 bit egg
(downloaded to my local machine) and got:
macshevitz:~ dannyshevitz$ sudo easy_install pymatlab-0.1.3-py2.6-linux-x86_64.
egg
Password:
Searching for pymatlab-0.1.3-py2.6-linux-x86-64.egg
Reading http://pypi.python.org/simple/pymatlab-0.1.3-py2.6-linux-x86_64.egg/
No local packages or download links found for pymatlab-0.1.3-py2.6-linux-
x86-64.egg
error: Could not find suitable distribution for
Requirement.parse('pymatlab-0.1.3-py2.6-linux-x86-64.egg')
I am in the same directory as the egg when I do this. I am certainly doing
something stupid, but don't know what it is.
thanks,
Danny
--
http://mail.python.org/mailman/listinfo/python-list
attach to process by pid?
Howdy, Is there any way to attach to an already running process by pid? I want to send commands from python to an application that is already running. I don't want to give the command name to subprocess.Popen. thanks, Danny -- http://mail.python.org/mailman/listinfo/python-list
Re: attach to process by pid?
> process has some kind of communication(s) interface; eg: > * some kind of listening socket > * some kind of I/O (pipe, stdin/stdout) It does have a stdin/stdout. How do I access it? thanks, D -- http://mail.python.org/mailman/listinfo/python-list
Re: attach to process by pid?
> Have a look at the SIMPL toolkit. http://www.icanprogram.com/06py/lesson1/lesson1.html > > This should be able to do exactly what you want. > > bob Does this work on Mac OS X? thanks, Danny -- http://mail.python.org/mailman/listinfo/python-list
calling 64 bit routines from 32 bit matlab on Mac OS X
Howdy, I have run into an issue that I am not sure how to deal with, and would appreciate any insight anyone could offer. I am running on Mac OS X 10.5 and have a reasonably large tool chain including python, PyQt, Numpy... If I do a "which python", I get "Mach-O executable i386". I need to call some commercial 3rd party C extension code that is 64 bit. Am I just out of luck or is there something that I can do? thanks, Danny -- http://mail.python.org/mailman/listinfo/python-list
virtualenv problem on win32
Howdy,
I'm trying to use virtualenv for the first time and having endless grief.
I have upgraded my python distribution to the latest 2.7 distribution and it
is completely clean. I have prepended my path environment variable with
c:\python27 and c:\python27\scripts.
I have installed:
setuptools 0.6c11
virtualenv 1.6
windows extensions (I have read some posts that this might be important...)
When I try to create a virtual environment at the shell prompt:
virtualenv ENV
I get the following error:
###
d:\>virtualenv ENV
New python executable in ENV\Scripts\python.exe
Installing setuptools
Complete output from command d:\ENV\Scripts\python.exe -c "#!python
\"\"\"Bootstra...sys.argv[1:])
" c:\python27\lib\site...ols-0.6c11-py2.7.egg:
Processing setuptools-0.6c11-py2.7.egg
creating d:\env\lib\site-packages\setuptools-0.6c11-py2.7.egg
Extracting setuptools-0.6c11-py2.7.egg to d:\env\lib\site-packages
Traceback (most recent call last):
File "", line 279, in
File "", line 240, in main
File "c:\python27\lib\site-packages\setuptools\command\easy_install.py", line
1712, in main
with_ei_usage(lambda:
File "c:\python27\lib\site-packages\setuptools\command\easy_install.py", line
1700, in with_ei_usage
return f()
File "c:\python27\lib\site-packages\setuptools\command\easy_install.py", line
1716, in
distclass=DistributionWithoutHelpCommands, **kw
File "c:\python27\Lib\distutils\core.py", line 152, in setup
dist.run_commands()
File "c:\python27\Lib\distutils\dist.py", line 953, in run_commands
self.run_command(cmd)
File "c:\python27\Lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "c:\python27\lib\site-packages\setuptools\command\easy_install.py", line
211, in run
self.easy_install(spec, not self.no_deps)
File "c:\python27\lib\site-packages\setuptools\command\easy_install.py", line
427, in easy_install
return self.install_item(None, spec, tmpdir, deps, True)
File "c:\python27\lib\site-packages\setuptools\command\easy_install.py", line
476, in install_item
dists = self.install_eggs(spec, download, tmpdir)
File "c:\python27\lib\site-packages\setuptools\command\easy_install.py", line
619, in install_eggs
return [self.install_egg(dist_filename, tmpdir)]
File "c:\python27\lib\site-packages\setuptools\command\easy_install.py", line
693, in install_egg
(os.path.basename(egg_path),os.path.dirname(destination)))
File "c:\python27\Lib\distutils\cmd.py", line 349, in execute
util.execute(func, args, msg, dry_run=self.dry_run)
File "c:\python27\Lib\distutils\util.py", line 401, in execute
func(*args)
File "c:\python27\lib\site-packages\setuptools\command\easy_install.py", line
996, in unpack_and_compile
unpack_archive(egg_path, destination, pf)
File "c:\python27\lib\site-packages\setuptools\archive_util.py", line 67, in u
npack_archive
driver(filename, extract_dir, progress_filter)
File "c:\python27\lib\site-packages\setuptools\archive_util.py", line 135, in
unpack_zipfile
z = zipfile.ZipFile(filename)
File "c:\python27\Lib\zipfile.py", line 712, in __init__
self._GetContents()
File "c:\python27\Lib\zipfile.py", line 746, in _GetContents
self._RealGetContents()
File "c:\python27\Lib\zipfile.py", line 786, in _RealGetContents
raise BadZipfile, "Bad magic number for central directory"
zipfile.BadZipfile: Bad magic number for central directory
...Installing setuptools...done.
Traceback (most recent call last):
File "c:\python27\scripts\virtualenv-script.py", line 8, in
load_entry_point('virtualenv==1.6', 'console_scripts', 'virtualenv')()
File "c:\python27\lib\site-packages\virtualenv-1.6-py2.7.egg\virtualenv.py", l
ine 745, in main
prompt=options.prompt)
File "c:\python27\lib\site-packages\virtualenv-1.6-py2.7.egg\virtualenv.py", l
ine 843, in create_environment
install_setuptools(py_executable, unzip=unzip_setuptools)
File "c:\python27\lib\site-packages\virtualenv-1.6-py2.7.egg\virtualenv.py", l
ine 571, in install_setuptools
_install_req(py_executable, unzip)
File "c:\python27\lib\site-packages\virtualenv-1.6-py2.7.egg\virtualenv.py", l
ine 547, in _install_req
cwd=cwd)
File "c:\python27\lib\site-packages\virtualenv-1.6-py2.7.egg\virtualenv.py", l
ine 813, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command d:\ENV\Scripts\python.exe -c "#!python
\"\"\"Bootstra...sys.argv[1:])
" c:\python27\lib\site...ols-0.6c11-py2.7.egg failed with error code 1
###
does anyone know what is going on?
thanks,
Danny
--
http://mail.python.org/mailman/listinfo/python-list
geospatial python and how to convert multilinestrings to kml
Howdy, I need to do some geospatial work and am a complete newbie at this. I have access to a PostGIS database and there are lots of MultiLineString objects. I want to run a python algorithm that determines a group of these MultiLineString objects and creates a KML file of the results. Is there a pythonic way (some existing module) to convert PostGIS MultiLineStrings to a KML file format? thanks, Danny -- http://mail.python.org/mailman/listinfo/python-list
problem doing unpickle in an exec statement
Howdy,
In my app I need to exec user text that defines a function. I want this
function to unpickle an object. Pickle breaks because it is looking for
the object definition that isn't in the calling namespace.
I have mocked up a simple example that shows the problem. Run this
first code (from create_pickle.py) to create the pickle.
create_pickle.py: (run this first)
#
import cPickle
# the pickle file name
file_name = 'd:\\temp\\test1.pickle'
# define a class
class Tree(object):
pass
def main():
# instantiate
t = Tree()
# create the sweet pickle
fp = open(file_name, 'wb')
cPickle.dump(t, fp)
fp.close()
# try to unpickle directly
fp = open(file_name, 'rb')
result = cPickle.load(fp)
fp.close()
print "unpickling directly works just fine, result = ", result
if __name__=='__main__':
main()
#
run this second:
exec_pickle.py
#
# this file shows a problem with sweet pickle in an exec statement
# the pickle file name
file_name = 'd:\\temp\\test1.pickle'
# code to be turned into a function
code_text = '''
def include():
print "this works!"
'''
# a function for creating functions
def create_fun(code_text):
clean_dict = {}
exec code_text in clean_dict
return clean_dict['include']
# include_fun is a bona fide function
include_fun = create_fun(code_text)
# this works
include_fun()
# now try to load the pickle in an exec statement
code_text = '''
def include(file_name):
print "processing file_name: ", file_name
import cPickle
fp = open(file_name, "rb")
result = cPickle.load(fp)
fp.close()
print "result = ", result
'''
# create the new include_fun
include_fun = create_fun(code_text)
# run it
include_fun(file_name)
#
Can anyone enlighten me what I need to do to exec_pickle.py
to get this to work?
thanks,
Danny
--
http://mail.python.org/mailman/listinfo/python-list
how to convert a multiline string to an anonymous function?
Simple question here:
I have a multiline string representing the body of a function. I have control
over the string, so I can use either of the following:
str = '''
print state
return True
'''
str = '''
def f(state):
print state
return True
'''
and I want to convert this into the function:
def f(state):
print state
return True
but return an anonmyous version of it, a la 'return f' so I can assign it
independently. The body is multiline so lambda doesn't work.
I sort of need something like:
def function_constructor(str):
f = eval(str) # What should this be
return f
functions = {}
for node in nodes:
function[node] = function_constructor(node.text)
I'm getting stuck because 'def' doesn't seem to work in an eval function,
and exec actually modifies the namespace, so I run into collisions if I use
the function more than once.
I know I'm missing something stupid here, but I'm stuck just the same...
thanks,
Danny
--
http://mail.python.org/mailman/listinfo/python-list
Re: how to convert a multiline string to an anonymous function?
Thanks All! you've solved my problem. D -- http://mail.python.org/mailman/listinfo/python-list
