Simple two-process client/server plotting with the following features:
- Plotting does not slow down calculations.
- User maintains control of the calculation (i.e. KeyboardInterrupts work).
The simplest approach is a multi-thread approach. In principle, one can run the computations in the main thread and plotting in a separate thread. This solution is sketched in thread.py but fails with most matplotlib_ backends due to their requirement of running in the main thread. A quick work-around is to run the computation in a secondary thread, but this precludes the user being able to interrupt the computation.
A nice feature of the python GIL is that one can be fairly confident about sharing data (a careful solution would require locks etc.)
This same solution should work with multiprocessing_, but this fails on my development platform (Mac OS X 10.5) with the following error:
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec(). Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
It seems that the most robust solution is to have the calculation and plotters run in completely separate processes. This has an added benefit:
- User can plot remotely.
One issue that needs to be addressed here (and in the multiprocessing_ solution) is the copying of data. One common use-case is that the plotter may be slower than the computation. Thus, intermediate data may be discarded and should not be sent across the network.
It seems that one should be able to use IPython_ to do this, but I have not found a simple way to do this yet.