Re: Bug in Jython2.7b4?
Jim Baker <[email protected]>
| Newsgroups | gmane.comp.lang.jython.devel |
|---|---|
| Message-ID | <CAOhO=aPvjE8VgFn5eudTa7D=vd6sgpRU=jnKvM-aH+jKnZwBLw@mail.gmail.com> |
Jython implements the module import lock, which is required for correct execution of Python imports. As Indra points out, this can readily set up a deadlock in the scenario you have here. You can see this behavior more explicitly by inspecting the module import lock directly, https://docs.python.org/2/library/imp.html#imp.lock_held Java also allows you to do deadlock detection: http://www.jython.org/jythonbook/en/1.0/Concurrency.html#deadlocks - Jim On Wed, Feb 25, 2015 at 8:41 PM, Indra Talip <[email protected]> wrote: > G'day David, > Spawning a thread and waiting for it as you are doing while using your code > as a module is explicitly warned against in the Python docs as having the > potential to cause a deadlock: > > Firstly, other than in the main module, an import should not have the side > effect of spawning a new thread and then waiting for that thread in any way. > Failing to abide by this restriction can lead to a deadlock if the spawned > thread directly or indirectly attempts to import a module. > > https://docs.python.org/2/library/threading.html#importing-in-threaded-code > > So I'm not sure that this is a fault with Jython. > > I would try moving the call to Event.wait() to be subsequent to your import > of that module so that you avoid the potential for deadlocking. > > Cheers > Indra > > On 26 February 2015 at 09:06, David Charles <[email protected]> > wrote: >> >> I tried to create an account at bugs.jython.org, but the registration >> e-mail never arrived. So, at Frank Wierzbicki's suggestion, I am reporting >> my experience here. I did not observe this behavior on previous releases of >> Jython. My demo program follows. >> >> ''' >> This program demonstrates that Jython2.7b4 fails to start a JavaFX >> Application if: >> >> 1. We are waiting for a threading.Event object, AND >> >> 2. This module is imported, rather than invoked as the entry >> point to the Python program. >> >> I think this is an important use case, because it enables me to hide >> JavaFX Application-start logic inside of a module and block until >> JavaFX initialzation is complete. >> >> I saw this behavior on Ubuntu Linux 11.04 and Windows7, Java 8u31. >> ''' >> >> import sys >> import threading >> import javafx.application.Application as Application >> import java.lang.Runnable as Runnable >> import java.lang.Thread as Thread >> >> javaFXIsReady = threading.Event() >> >> class MyApplication(Application): >> >> @classmethod >> def main(cls, args): >> MyApplication.launch(cls, args) >> >> def start(self, primaryStage): >> print 'MyApplication.start() was called.' >> javaFXIsReady.set() >> >> class MyRunnable(Runnable): >> >> def run(self): >> MyApplication.main(sys.argv) >> >> thread = Thread(MyRunnable()) >> thread.start() >> >> if __name__ == '__main__': >> print 'The module is the program entry point.' >> print 'So, MyApplication.start() will get called.' >> else: >> print 'The module was imported.' >> print 'So, MyApplication.start() will NOT get called.' >> >> javaFXIsReady.wait() >> >> >> >> ------------------------------------------------------------------------------ >> Dive into the World of Parallel Programming The Go Parallel Website, >> sponsored >> by Intel and developed in partnership with Slashdot Media, is your hub for >> all >> things parallel software development, from weekly thought leadership blogs >> to >> news, videos, case studies, tutorials and more. Take a look and join the >> conversation now. http://goparallel.sourceforge.net/ >> _______________________________________________ >> Jython-dev mailing list >> [email protected] >> https://lists.sourceforge.net/lists/listinfo/jython-dev >> > > > > -- > Indra Talip > > ------------------------------------------------------------------------------ > Dive into the World of Parallel Programming The Go Parallel Website, > sponsored > by Intel and developed in partnership with Slashdot Media, is your hub for > all > things parallel software development, from weekly thought leadership blogs > to > news, videos, case studies, tutorials and more. Take a look and join the > conversation now. http://goparallel.sourceforge.net/ > _______________________________________________ > Jython-dev mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/jython-dev > -- - Jim jim.baker@{colorado.edu|python.org|rackspace.com|zyasoft.com} twitter.com/jimbaker github.com/jimbaker bitbucket.com/jimbaker ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/