[Jython-checkins] jython: Avoid private member access in subprocess.py. Contributes to #2656.

jeff.allen jython-checkins at python.org
Tue May 8 18:16:18 EDT 2018


https://hg.python.org/jython/rev/61eda8fd9356
changeset:   8163:61eda8fd9356
user:        Jeff Allen <ja.py at farowl.co.uk>
date:        Tue May 08 22:18:18 2018 +0100
summary:
  Avoid private member access in subprocess.py. Contributes to #2656.

In Java 9, Process has a pid() method so we no longer have to setAccessible().

files:
  Lib/subprocess.py |  8 +++++++-
  1 files changed, 7 insertions(+), 1 deletions(-)


diff --git a/Lib/subprocess.py b/Lib/subprocess.py
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -432,6 +432,7 @@
     import java.io.FileNotFoundException
     import java.lang.IllegalArgumentException
     import java.lang.IllegalThreadStateException
+    import java.lang.Process
     import java.lang.ProcessBuilder
     import java.lang.System
     import java.lang.Thread
@@ -1417,7 +1418,12 @@
             else:
                 return field
 
-        if os._name not in _win_oses:
+        if hasattr(java.lang.Process, "pid"): # Java 9 onwards
+
+            def _get_pid(self, pid_field=None):
+                return self._process.pid()
+
+        elif os._name not in _win_oses:
 
             def _get_pid(self, pid_field='pid'):
                 field = self._get_private_field(self._process, pid_field)

-- 
Repository URL: https://hg.python.org/jython


More information about the Jython-checkins mailing list