#129 Pasting into console app doesn't work with unbuffered=True

open
nobody
None
5
2012-10-25
2012-10-25
Michael Herrmann
No

OS: Win 7 32 bit
Python version: 2.7.3
Py2exe version: py2exe-0.6.9.win32-py2.7

This bug is very simple to reproduce:

main.py (attached):

import code

if __name__ == '__main__':
code.interact()

setup.py (attached):

from distutils.core import setup
import py2exe

setup(
console=[{
'script': 'main.py'
}],
options={
'py2exe': {
'unbuffered': True
}
}
)

test.txt (attached):

1
2

Steps to reproduce the problem:

1. Compile with `python setup.py py2exe`.
2. Start dist/main.exe.
3. Copy the contents of test.txt to the clipboard.
4. Paste into the main.exe console. You should see:
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> 1
1
>>> 2
5. Press Enter.

What is the expected outcome?

Pressing Enter should result in 2 being evaluated by the interactive console, so 2 should be displayed:
...
>>> 2
2
>>>

What happens instead?

The console "hangs" and does not process the input 2. Pressing Enter again results in the following output:
>>> 2

Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'm' is not defined
>>>

Further information:

It seems like the Python interactive console that was invoked by code.interact() does not receive the input "2" but "m\x00".

Everything works fine when py2exe option 'unbuffered' is set to True.

Discussion

  • main.py, setup.py and test.txt

     
    Attachments