Message9867

Author kevinmcmurtrie
Recipients kevinmcmurtrie, zyasoft
Date 2015-04-15.21:07:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1429132076.05.0.8564788463.issue2321@psf.upfronthosting.co.za>
In-reply-to
Content
Code is breaking where the provided PySystemState must differ in some way from the default prototype - argv, path, stdout, stderr, stdin, etc.  Every call to Py.getSystemState() scattered throughout Jython potentially returns a new object until something calls ThreadState.enterRepr().  In debugging, many PySystemState instances may come and go before reaching that point.

Some refactoring is needed in Jython.  The problem is that ThreadState has become the real execution state but it's not very well exposed or managed.  PySystemState is well exposed but it's just a field in a temporary object.

My current workaround is to get my hands on the ThreadState and keep a hard reference:

final ThreadState ts= Py.getThreadState(newSystemState);
ts.systemState = newSystemState; 
 ... save ts somewhere so it doesn't evaporate ...

It's non-obvious and what it does to ThreadState.systemState isn't really legit.  It leaves a very high risk of future code calling Py.setSystemState(), because that looks right, and then failing for mysterious reasons.
History
Date User Action Args
2015-04-15 21:07:56kevinmcmurtriesetmessageid: <1429132076.05.0.8564788463.issue2321@psf.upfronthosting.co.za>
2015-04-15 21:07:56kevinmcmurtriesetrecipients: + kevinmcmurtrie, zyasoft
2015-04-15 21:07:56kevinmcmurtrielinkissue2321 messages
2015-04-15 21:07:55kevinmcmurtriecreate