-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GetOverlappedResult implementation #115
Conversation
Ooops! Something strange is going on: all tests are failing the same way, in line 49 of test_overlapped.py... Given that the assertion is failing, WriteFile is returning something other than zero which, I presume, may be indicating that overlapped IO wasn't properly triggered... :/ My envirnonment is Python 2.7 on 32 bit Windows 7 and runs the test successfuly... Could you check whether it fails or passes on yours? PS: Any other idea as to what might be the issue here? Thanks. |
|
||
https://msdn.microsoft.com/en-us/library/ms683209 | ||
|
||
:param HANDLE hFile: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need the path to the class here so it can be linked properly in the documentation.
When I first proposed pywincffi as the thing to replace pywin32 in Twisted I asked what else might we be able to replace and pyserial/ctypes was one the list. It's not as high as the other stuff in #69 but it's probably something worth investigating later on.
Not sure and I don't have access to my Windows VM today so I'll have to check tomorrow or Thursday depending on work. It's not clear just from the test output why this could be happening so for now I don't have a better answer. If I had to guess it might a subtle timing issue of some kind and/or have something to do with the flags being passed into the functions during the tests (WriteFile for example has a few flags specifically for overlapped I/O). I'll take a look more closely when I have access to a VM again. Other than all that, code looks pretty good. Just had a couple of small comments but I don't see anything wrong overall with style or the major parts of the implementation. Once again, thanks for the help! |
Sorry for the delay! So, this passes locally for me using Python 3.4 and 3.5. I expect the same results with Python 2.7 but I need to fix something in the build first:
|
Merged #117, your tests work fine in Python 2.7 too so I'm still not sure exactly why this fails on AppVeyor. |
(quick feedback) Thanks for your review and comments. I've been very busy these days as I'm off for a one week vacation... Hopefully I'll be able do some improvements tomorrow morning. Otherwise I'll only be able to get back to this in about two weeks, I guess. :/ |
Current coverage is 98.98% (diff: 100%)
|
Progress:
Any pointers? |
|
||
_ = WriteFile(handle, file_contents, lpOverlapped=ovr) | ||
error_code, _ = self.GetLastError() | ||
self.assertIn(error_code, (lib.ERROR_IO_PENDING, 0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interestingly, I merged some code yesterday you could use here:
https://github.com/opalmer/pywincffi/blob/master/pywincffi/dev/testutil.py#L295
Basically, replace assertIn and SetLastError with:
self.maybe_assert_last_error(lib.ERROR_IO_PENDING)
The one check is failing because you're missing some coverage in overlapped.py: https://codecov.io/gh/opalmer/pywincffi/pull/115/compare If possible, it would be nice to have a test which covers that code. You could probably use |
Two questions before proceeding:
|
Merging from the current master is fine.
Correct yes. Sorry I should have caught this in the review... |
I think this is ready for merging -- pending your review, of course.
PS: I'll be for a couple of weeks on vacation. :) |
Reviewed and I agree, merging.
I'll try to put some time into these if I have the time over the next couple of weeks.
Enjoy your vacation and thanks again! |
Sharing GetOverlappedResult implementation, which is actually very simple.
I found testing a bit more complex and banged my head around it for a while.
The key issue in the simplest test case I could devise -- based on doing an overlapped WriteFile -- was the fact that when doing overlapped IO, WriteFile (and others) set the GetLastError to ERROR_IO_PENDING and the TestCase cleanups were checking and complaining about it not being 0. All seems fine after I figured it out, validated it and SetLastError to 0 afterwards.
At first I tried going for a ReadFile based test, but I think that will require some changes to the existing ReadFile implementation: the current approach does not seem to work because it is returing a bytes object which, under overlapped IO, is not available at that time... Only after the overlapped IO completes and is waited on, for example, via GetOverlappedResult. At first sight, I'm not sure of a somewhat Pythonic approach to that. :)
Submitting PR for review and maybe some discussion around this topic.
PS: Regarding Twisted, it seems that GetOverlappedResult is used in serial port code using ReadFile/WriteFile and others so the overlapped ReadFile will need thought.
PPS: The serial code in Twisted seems to depend on pyserial which, at first glance, is using ctypes to reach out to the underlying windows APIs (good, it would be a mess for Twisted if it depended on pywin32! offtopic: maybe someday pyserial can be built on top of pywincffi, who knows)