Persist a Python class instance across command-line calls (without shelve)?
<p>I have an existing Python class that is used for data capture. It has start() and stop() methods to start and stop the data capture. Right now this class is used in a single Python script, e.g.:</p>

<pre><code>dataGrabber = DataGrabber()
dataGrabber.start()
# do a bunch of stuff...
dataGrabber.stop()
</code></pre>

<p>We want to break out the start and stop functionality and be able to start and stop the data capture from the command line, e.g.:</p>

<pre><code>python CaptureData.py start
&lt;&lt;&lt; go off and do something else &gt;&gt;&gt;
python CaptureData.py stop
</code></pre>

<p>I need a way for CaptureData.py to create an instance of the DataGrabber class when the script is called with the "start" argument, save that class instance somehow, and have it be accessible when I call the script with the "stop" argument.</p>

<p>I tried using shelve, but the DataGrabber class has tons of instance methods, and Python can't pickle instance methods.</p>

<p>Any ideas? Is there any way I can do this?</p>
