Message10979

Author andrewparks
Recipients andrewparks, zyasoft
Date 2016-10-27.14:59:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1477580354.14.0.39154108109.issue2530@psf.upfronthosting.co.za>
In-reply-to
Content
Jim, thank you so much for your responses. I did not realise until you pointed it out that it was possible to interrupt a PythonInterpreter.exec() by simply doing a Thread.interrupt().

I was not aware of shutdownInterpreter(), and it seems to be the solution I was looking for. In fact, I didn't even realise from the Jython docs that I could use Thread.interrupt() to abort execution.

Thank you very much for helping me understand how to resolve this problem now. So although I know to fix my issue, a way to shutdown reset the PythonInterpreter rather than simply shut it down is still very welcome.

FYI, for anyone else coming across this page, here is the code that I didn't realise until now that I could have written to abort PythonInterpreter.exec():

PythonInterpreter pi = new PythonInterpreter();

    Thread jythonThread = new Thread(new Runnable() {
      @Override
      public void run() {
        pi.exec("while 1: print 'hello'");
      }
    });

    jythonThread.start();

    new Thread(new Runnable() {
      @Override
      public void run() {
        try {
          Thread.sleep(2000);
          jythonThread.interrupt();
        }
        catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }).start();
History
Date User Action Args
2016-10-27 14:59:14andrewparkssetmessageid: <1477580354.14.0.39154108109.issue2530@psf.upfronthosting.co.za>
2016-10-27 14:59:14andrewparkssetrecipients: + andrewparks, zyasoft
2016-10-27 14:59:14andrewparkslinkissue2530 messages
2016-10-27 14:59:13andrewparkscreate