Thanks a lot for the help!
On Tue, 30 Mar 1999, Hugunin, Jim <hugunin@...> wrote:
> > In Java, you may not use object's wait method until you get the
> > ownership on its monitor (that means that your call must be inside of
> > code block synchronized on this object). In jpython, you had
> As usual, Pavel's answer here is completely right if you ignore the existence of JPython-1.1a3. I figure we'd better give him a hint where he can find that so that his answers can be even more useful:
> In JPython-1.1a3 there is a new (undocumented) module called "synchronize". This is designed to let you use Java-style synchronization in your JPython programs. It exports two functions, make_synchronized and apply_synchronized. make_synchronized is designed to be used as shown in the example below to make a method synchronized (the synchronization occurs on the first argument of any callable -- for methods this is self). apply_synchronized could be used to do the same thing in a functional fashion. It works just like the apply function (from builtins) but takes a special first argument that is an object to synchronize on while evaluating the callable.
> from javax import swing
> from java.lang import Object
> from synchronize import make_synchronized
> class Chooser(Object):
> def __init__(self, items):
> self.list = swing.JList(items)
> okbutton = swing.JButton("Ok", actionPerformed=self.onclick)
> panel = swing.JPanel()
> panel.add(self.list, "Center")
> panel.add(okbutton, "South")
> frame = swing.JFrame(title="Choose an Item")
> def onclick(self, event):
> self.result = self.list.selectedIndex
> onclick = make_synchronized(onclick)
> def choose(self):
> return self.result
> choose = make_synchronized(choose)
> items = ['apple', 'bannana', 'cherry']
> print Chooser(items).choose()
> import sys
> JPython-Interest maillist - JPython-Interest@...
JPython-Interest maillist - JPython-Interest@...