peterbrittain / asciimatics

A cross platform package to do curses-like operations, plus higher level APIs and widgets to create text UIs and ASCII art animations
Apache License 2.0
3.64k stars 238 forks source link

Windows screen interrupt error fix #220

Closed odd-meta closed 5 years ago

odd-meta commented 5 years ago

Issues fixed by this PR

Fix for argument error to win32.event.WaitForSingleObject found on Windows 10 with Python 2.7.15.

What does this implement/fix?

Attempting to run samples/contact_list.py on Windows 10 with Python 2.7.15 without this fix results in the following error:

File "C:\Python27\lib\site-packages\asciimatics\screen.py", line 2107, in wait_for_input
    rc = win32event.WaitForSingleObject(self._stdin, timeout * 1000)
SystemError: ..\Objects\longobject.c:463: bad argument to internal function

Not sure if this is the right fix, or the best fix, but samples/contact_list.py runs after it is applied, as do all the tests in the tests directory.

coveralls commented 5 years ago

Coverage Status

Coverage remained the same at 96.287% when pulling bf15b6b5593868c4281b0d50d9b85ff7682f3cfe on odd-meta:master into 273bd86f4f579520749c43da1adb58d027959861 on peterbrittain:master.

coveralls commented 5 years ago

Coverage Status

Coverage remained the same at 96.287% when pulling 023f883c577e1802f0fbbeac802de344614dbb96 on odd-meta:master into 273bd86f4f579520749c43da1adb58d027959861 on peterbrittain:master.

peterbrittain commented 5 years ago

There's something strange going on here...

I suspect that something has changed in pywin32... Can you please confirm what version you have installed?

odd-meta commented 5 years ago

From my C:\Python27\Lib\site-packages\pywin32-224.dist-info\METADATA file:

Metadata-Version: 2.0
Name: pywin32
Version: 224
Summary: Python for Window Extensions
Home-page: https://github.com/mhammond/pywin32
Author: Mark Hammond (et al)
Author-email: mhammond@skippinet.com.au
License: PSF
Description-Content-Type: UNKNOWN
Platform: UNKNOWN
peterbrittain commented 5 years ago

Thanks. I don't have access to my windows machines for a couple of weeks, so can't compare with them, but given the release date for version 224, I know that I'll be using an earlier version.

In the meantime, could you please confirm whethr you are using a 32 or 64 bit build of python and how you installed your version of pywin32? Also if you could try a version before build 220, I think you'd be in the right ballpark for the last time I installed the package.

odd-meta commented 5 years ago

Python 2.7.15 appears to be 64 bit Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)] on win32

I installed pywin32 via pip during dependency install for the first run of asciimatics.

Version Testing Notes

For this testing I pip uninstalled that copy of pywin32 and obtained installer versions for all testing outlined below. For testing of version 221 and higher installers were sourced from: https://github.com/mhammond/pywin32/releases. For these I used the pywin32-vvv.win-amd64-py2.7.exe variants. For versions of pywin32 older than version 221 installers were sourced from https://sourceforge.net/projects/pywin32/files/pywin32/.

I based my testing on versions listed in the pywin32 release history with 210 omitted for age. Some of the steps below are redundant; I tried to keep the steps and order as similar as possible to help me not screw up testing.

First Test [installer pywin32 224 with fresh asciimatics]

Observed the same error as before

  File "C:\Python27\lib\site-packages\asciimatics\screen.py", line 2107, in wait_for_input
    rc = win32event.WaitForSingleObject(self._stdin, timeout * 1000)
SystemError: ..\Objects\longobject.c:463: bad argument to internal function

Second Test [installer pywin32 214 with fresh asciimatics]

Observed a different error

  File "C:\Python27\lib\site-packages\asciimatics\screen.py", line 2107, in wait_for_input
    rc = win32event.WaitForSingleObject(self._stdin, timeout * 1000)
TypeError: integer argument expected, got float

Third Test [installer pywin32 223 with fresh asciimatics]

Observed the same error as initial error

  File "C:\Python27\lib\site-packages\asciimatics\screen.py", line 2107, in wait_for_input
    rc = win32event.WaitForSingleObject(self._stdin, timeout * 1000)
SystemError: ..\Objects\longobject.c:463: bad argument to internal function

Fourth Test [installer pywin32 222 with fresh asciimatics]

Observed the same error as initial error

  File "C:\Python27\lib\site-packages\asciimatics\screen.py", line 2107, in wait_for_input
    rc = win32event.WaitForSingleObject(self._stdin, timeout * 1000)
SystemError: ..\Objects\longobject.c:463: bad argument to internal function

misc notes

I am suspicious that this is a real issue until it can be replicated on a Windows machine beyond my own. Like any development-ish machine this one has drifted pretty far from a 'normal' configuration and setup over the years. If I had a functional Windows VM handy I would give that a try, unfortunately I do not.

peterbrittain commented 5 years ago

That was a rigorous response! Thanks.

I'm beginning to wonder if I somehow got away with a floating point number when I developed this function and am now being picked up on that by newer builds of pywin32. If casting to an int instead of a long (so that it will work on python 3) fixes it for you, I'm happy to take that as the fix instead.