Brandon,

Please see the section on thread interruption in the Jython book chapter on concurrency:
http://jythonpodcast.hostjava.net/jythonbook/en/1.0/Concurrency.html#interruption

This section discusses how to use Python's standard threading library with the enhancements available under Java, such as interruption. Also 2.5.2 now provides support of java.lang.Thread methods without monkeypatching.

- Jim

On Thu, Aug 12, 2010 at 9:07 AM, Brandon Pedersen <bpedman@gmail.com> wrote:
On Wed, Aug 11, 2010 at 3:30 PM, Raghuram Devarakonda
<draghuram@gmail.com> wrote:
> I tried this example with trunk and I do see the print statement as a
> result of the interruption.  I don't have 2.5.1 handy in order to
> verify whether this is something that got fixed in the trunk. Will you
> be able to test with Jython from trunk?

I will have to try this again later. I found a different method to do
what I want...and cleaner, but I will see if I can reproduce with
trunk. It may have to do with handling sockets which is what I am
doing. Here is a more complete example of my previous work if you want
to try again:

class Listener(Thread): # <-- this is a java.lang.Thread, not
threading.Thread since threading.Thread does not have interrupt()

   def __init__(self, port=0):
       Thread.__init__(self, "Listener")
       self.port = port
       self._log = StringIO()
       self.captured_output = None
       self._client_socket = None
       self._server = None

   def run(self):
       self._server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
       self._server.bind(("", self.port))
       self._server.listen(1)
       self.port = self._server.getsockname()[1]

       log.debug("Listener started on port %d" % self.port)

       self._client_socket, address = self._server.accept()

       log.debug("Listener got a connection from " + str(address))

       try:
           while True:
               data = self._client_socket.recv(1024)
               self._log.write(data)
       finally:
           print "in finally block"
           try:
               if self._client_socket:
                   self._client_socket.close()
           except: pass
           try:
               if self._server:
                   self._server.close()
           except: pass
           self.captured_output = self._log.getvalue()
           log.trace("%s output:\n%s" % (self.getName(), self.captured_output))
           self._log.close()

if __name__ == "__main__":
  tmp = Listener()
  tmp.start()
  # start something that connects to the port so socket.recv() will block
  tmp.interrupt()
  # the print statement in the finally block (or anything in an
except block) is never seen

Thanks,

-Brandon

------------------------------------------------------------------------------
This SF.net email is sponsored by

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev
_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users