Question

A Python program is running on a shell, how to communicate with it using another Python shell?

Let say we have started running a very long simulation which is going well on a shell. We realised a need to capture the current values, say, in a numpy array.

How to pause the simulation, capture desired values and resume using another Python shell?

No correct solution

OTHER TIPS

Here is a package to work with subprocesses, capture an output: http://pymotw.com/2/subprocess/

For instance to capture an output, you can check_output

import subprocess

output = subprocess.check_output(['ls', '-1'])
print 'Have %d bytes in output' % len(output)
print output

Your best bet is to use IPython. It runs code in one or more kernels, which can then be communicated with by different subprocesses. All of the values in the running kernel can be shared, allowing you to do exactly what you're looking to do. Sites like Wakari offer free IPython Notebook instances so you can experiment.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top