Issue2592

classification
Title: sys.cleanup() in PythonInterpreter close() method closing thread pool _socket.NIO_GROUP in _socket.py
Type: behaviour Severity: major
Components: Core Versions: Jython 2.7
Milestone: Jython 2.7.1
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: psterdale, zyasoft
Priority: Keywords:

Created on 2017-05-17.08:11:36 by psterdale, last changed 2017-05-19.02:58:45 by zyasoft.

Files
File name Uploaded Description Edit Remove
socket_threadpool_issue.zip psterdale, 2017-05-17.11:57:08 Sample python script , java code and logs
Messages
msg11374 (view) Author: Parisa (psterdale) Date: 2017-05-17.08:11:35
sys.cleanup() in org.python.util.PythonInterpreter.close() method closing thread pool _socket.NIO_GROUP in _socket.py

Is thread pool needs to be recreated create_connection() function in _socket.py if it is shutdown?
or Can we use org.python.util.PythonInterpreter instance without closing ? repeatedly shared across multiple threads?

Please suggest...

Thank you.
msg11375 (view) Author: Parisa (psterdale) Date: 2017-05-17.11:57:08
I have added below lines of code to create_connection() function in _socket.py 

    if NIO_GROUP.isShutdown():
        log.debug("Theard pool is shutdown. Recreating...")
        global NIO_GROUP
        NIO_GROUP = NioEventLoopGroup(_NUM_THREADS, DaemonThreadFactory("Jython-Netty-Client-%s"))
        sys.registerCloser(_shutdown_threadpool)    

Please suggest if there is any better way to handle this...
PFA sample java code and script to reproduce the issue.
Also logs from _socket.py before and after fix.
msg11382 (view) Author: Jim Baker (zyasoft) Date: 2017-05-19.02:58:45
Interesting. I didn't consider lifecycle issues of PySystemState/PythonIntepreter and how it interacts with such Netty threadpools. Something like this could be the right answer, possibly on a per PySystemState to avoid causing ClassLoaders for Jython to not GC. In general we would prefer to avoid have such global singletons, convenient as they may have been for perhaps the most common case.
History
Date User Action Args
2017-05-19 02:58:45zyasoftsetnosy: + zyasoft
messages: + msg11382
2017-05-17 11:57:09psterdalesetfiles: + socket_threadpool_issue.zip
messages: + msg11375
2017-05-17 08:11:37psterdalecreate