Repository: spyder-ide/spyder

Issue:
Spyder 4.0.0 gives an error when restarting it in Python 2.7
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

### Issue Report Checklist

* [x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [x] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [x] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [x] Tried basic troubleshooting (if a bug/error)
    * [x] Restarted Spyder
    * [x] Reset preferences with ``spyder --reset``
    * [x] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [x] Tried the other applicable steps from the Troubleshooting Guide
* [x] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below

* [ ] Could not reproduce inside ``jupyter qtconsole`` (if console-related)

## Problem Description

Spyder 4.0.0 is crashing while loading IPython console in Anaconda 2019.07. It crashes with a python has stopped working error (see below) . I recreated the same issue in Anaconda 2019.10 (installed with "Just for me"). The issue occurs in both base environment and on creating a separate environment.

I am quite new to Spyder so any help is appreciated.

### What steps reproduce the problem?

1. Create new environment with `python=2.7 spyder=4.0.0`
2. Start spyder from Anaconda Prompt

### What is the expected output? What do you see instead?

Spyder should load but Python error is showed instead.

![image](https://user-images.githubusercontent.com/58021697/70614403-81ce2480-1c30-11ea-9955-441a53310583.png)

## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 4.0.0
* Python version: 2.7.17
* Qt version: 5.6.2
* PyQt version: 5.6.0
* Operating System name/version: Windows 10 64 bit


Discussion:
Please open a terminal (cmd.exe, Terminal.app or xterm), run the following command:

    spyder --debug-info verbose --debug-output file

and upload here the file called `spyder-debug.log`, which is created in the same directory where you ran the command above.
Attaching the debug log.

[spyder-debug.log](https://github.com/spyder-ide/spyder/files/3959156/spyder-debug.log)

@dalthviz, can you reproduce this one?
Ping @dalthviz again. @dalthviz, is Spyder working with Python 2.7 on Windows?
@ccordoba12 Spyder is working for me. Although when setting `SPYDER_DEBUG=3` I can see a message in the IPython Console:

![image](https://user-images.githubusercontent.com/16781833/71758191-b1a4cc80-2e6a-11ea-8ebf-19fbac48bed6.png)

Also when changing the language the following traceback is shown (from Spanish to English in my case):

```traceback
  File "C:\Users\Daniel\Anaconda3\envs\py27\lib\site-packages\spyder\app\restart.py", line 299, in <module>
    main()
  File "C:\Users\Daniel\Anaconda3\envs\py27\lib\site-packages\spyder\app\restart.py", line 246, in main
    if not is_pid_running(pid):
  File "C:\Users\Daniel\Anaconda3\envs\py27\lib\site-packages\spyder\app\restart.py", line 78, in is_pid_running
    return _is_pid_running_on_windows(pid)
  File "C:\Users\Daniel\Anaconda3\envs\py27\lib\site-packages\spyder\app\restart.py", line 55, in _is_pid_running_on_windows
    stdoutdata = to_text_string(stdoutdata)
  File "C:\Users\Daniel\Anaconda3\envs\py27\lib\site-packages\spyder\py3compat.py", line 151, in to_text_string
    return unicode(obj)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position 9: ordinal not in range(128)
```
I'm unsure if both issues are related though


Resolving patch:
diff --git a/spyder/app/restart.py b/spyder/app/restart.py
--- a/spyder/app/restart.py
+++ b/spyder/app/restart.py
@@ -28,7 +28,7 @@
 
 # Local imports
 from spyder.config.base import _, get_image_path
-from spyder.py3compat import to_text_string
+from spyder.utils.encoding import to_unicode
 from spyder.utils.qthelpers import qapplication
 from spyder.config.manager import CONF
 
@@ -52,7 +52,7 @@ def _is_pid_running_on_windows(pid):
                                stderr=subprocess.STDOUT,
                                startupinfo=startupinfo)
     stdoutdata, stderrdata = process.communicate()
-    stdoutdata = to_text_string(stdoutdata)
+    stdoutdata = to_unicode(stdoutdata)
     process.kill()
     check = pid in stdoutdata
 


Test patch: