Re: Bug in Jython2.7b4?

Indra Talip <[email protected]>
Newsgroups gmane.comp.lang.jython.devel
Message-ID <CAE+gEVcYhCHNTMnX5vC71vU8e0_c1bD4OLp3SFrVNa3mRpxhtA@mail.gmail.com>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.