Permalink
Browse files

Setting PYTHONUNBUFFERED in the proper place. No longer changing the …

…default encoding -- using PYTHONIOENCODING instead (even though it's not supported in all Python versions).
  • Loading branch information...
1 parent 127032a commit 0ee184c4456145b391f68137da2f71637fc06443 @fabioz committed Mar 12, 2014
@@ -265,9 +265,12 @@ private static Process createProcess(ILaunch launch, String[] envp, String[] cmd
//Not using DebugPlugin.ATTR_CONSOLE_ENCODING to provide backward compatibility for eclipse 3.2
String encoding = launch.getAttribute(IDebugUIConstants.ATTR_CONSOLE_ENCODING);
if (encoding != null && encoding.trim().length() > 0) {
- String[] s = new String[envp.length + 3];
+ String[] s = new String[envp.length + 4];
System.arraycopy(envp, 0, s, 0, envp.length);
+ //We need python to run unbuffered.
+ s[s.length - 4] = "PYTHONUNBUFFERED=1";
+
//This is used so that we can get code-completion in a debug session.
s[s.length - 3] = "PYDEV_COMPLETER_PYTHONPATH="
+ PydevPlugin.getBundleInfo().getRelativePath(new Path("pysrc")).toString();
@@ -1,9 +1,12 @@
'''
This module will:
- - set the default encoding for python so that it'll print_ things correctly to the console.
- change the input() and raw_input() commands to change \r\n or \r into \n
- execute the user site customize -- if available
- change raw_input() and input() to also remove any trailing \r
+
+ Up to PyDev 3.4 it also was setting the default encoding, but it was removed because of differences when
+ running from a shell (i.e.: now we just set the PYTHONIOENCODING related to that -- which is properly
+ treated on Py 2.7 onwards).
'''
DEBUG = 0 #0 or 1 because of jython
@@ -40,78 +43,6 @@
pass
-
-if not IS_PYTHON_3K: #For Python 3.0, the PYTHONIOENCODING should already treat that correctly.
- #-------------------------------------------------------------------------------------------------------------------
- #check if the encoding has been specified for this launch...
-
- #set the encoding with the encoding_config file that should've been created
- #before launching the last application (it'll be removed after we get its contents)
- try:
- import os
- new_encoding = os.environ.get('PYDEV_CONSOLE_ENCODING')
- if new_encoding and new_encoding.strip():
- encoding = new_encoding.strip()
- if DEBUG:
- sys.stdout.write('encoding from env (PYDEV_CONSOLE_ENCODING): %s\n' % (encoding,))
- except:
- #ok, just ignore it if we couldn't get it
- if DEBUG:
- import traceback;traceback.print_exc() #@Reimport
-
-
-
- #-------------------------------------------------------------------------------------------------------------------
- if not encoding:
- #Jython
- try:
- from java.lang import System
- except ImportError:
- pass
- else:
- #that's the way that the encoding is specified in WorkbenchEncoding.getWorkbenchDefaultEncoding
- encoding = System.getProperty("file.encoding", "")
- if DEBUG:
- sys.stdout.write('encoding from "file.encoding": %s\n' % (encoding,))
-
-
- #-------------------------------------------------------------------------------------------------------------------
- if not encoding:
- #Python: get the default system locale (if possible)
- try:
- import locale
- except ImportError:
- if DEBUG:
- import traceback;traceback.print_exc() #@Reimport
- else:
- loc = locale.getdefaultlocale()
- if loc[1]:
- #ok, default locale is set (if the user didn't specify any encoding, the system default should be used)
- encoding = loc[1]
- if DEBUG:
- sys.stdout.write('encoding from "locale": %s\n' % (encoding,))
-
-
- #-------------------------------------------------------------------------------------------------------------------
- #if unable to get the encoding, the 'default' encoding is UTF-8
- if not encoding:
- encoding = "UTF-8"
-
-
-
- #-------------------------------------------------------------------------------------------------------------------
- #and finally, set the encoding
- try:
- if encoding:
- if DEBUG:
- sys.stdout.write('Setting default encoding: %s\n' % (encoding,))
- sys.setdefaultencoding(encoding) #@UndefinedVariable (it's deleted after the site.py is executed -- so, it's undefined for code-analysis)
- except:
- #ignore if we cannot set it correctly
- if DEBUG:
- import traceback;traceback.print_exc() #@Reimport
-
-
try:
import org.python.core.PyDictionary #@UnresolvedImport @UnusedImport -- just to check if it could be valid
def DictContains(d, key):
@@ -161,7 +92,7 @@ def DictContains(d, key):
#Now, execute the default sitecustomize
try:
import sitecustomize #@UnusedImport
- sitecustomize.__pydev_sitecustomize_module__=__pydev_sitecustomize_module__
+ sitecustomize.__pydev_sitecustomize_module__ = __pydev_sitecustomize_module__
except:
pass
@@ -178,7 +178,6 @@ public static Process createProcess(String[] cmdarray, String[] envp, File worki
//Always remove PYTHONHOME from the default system env, as it doesn't work well with multiple interpreters.
env.remove("PYTHONHOME");
- env.put("PYTHONUNBUFFERED", "1");
return env;
}

0 comments on commit 0ee184c

Please sign in to comment.