Title: ImportError when importing in multiple PyScriptEngine concurrently
Type: crash Severity: normal
Components: Core Versions: Jython 2.7
Milestone: Jython 2.7.2
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: jeff.allen, tcdelaney
Priority: Keywords:

Created on 2017-11-08.01:34:17 by tcdelaney, last changed 2018-02-25.22:45:22 by jeff.allen.

msg11652 (view) Author: Tim Delaney (tcdelaney) Date: 2017-11-08.01:34:15
I have an application which creates multiple PyScriptEngine instances on different threads. If multiple threads concurrently try to import I often get errors like:

Traceback (most recent call last):
  File ".\", line 34, in <module>
    import threading
  File ".\lib\jython-standalone-2.7.1.jar\Lib\", line 88, in <module>
AttributeError: type object 'java.lang.Thread' has no attribute 'State'


Traceback (most recent call last):
  File ".\", line 44, in <module>
    import gzip
  File ".\lib\jython-standalone-2.7.1.jar\Lib\", line 10, in <module>
  File ".\lib\jython-standalone-2.7.1.jar\Lib\", line 69, in <module>
  File ".\lib\jython-standalone-2.7.1.jar\Lib\", line 50, in <module>
ImportError: cannot import name DEFAULT_BUFFER_SIZE

Whilst I haven't been able to verify it, it appears to only be when importing Java classes.

By experimentation, if only a single thread is importing at a time the errors do not occur. As a workaround for my application I'm using a global import lock rather than an import lock per PySystemState, which seems to have resolved the issue. It's possible this is overkill and only part of the import process needs to be protected with a global lock.
msg11718 (view) Author: Jeff Allen (jeff.allen) Date: 2018-02-25.22:45:22
Things not having attributes when you know they do, and concurrency is in play, is reminiscent of #2609. A good thing to check in 2.7.2 beta, when it appears (or build your own alpha).
Date User Action Args
2018-02-25 22:45:22jeff.allensetnosy: + jeff.allen
messages: + msg11718
milestone: Jython 2.7.1 -> Jython 2.7.2
2017-11-08 01:34:17tcdelaneycreate