-
Notifications
You must be signed in to change notification settings - Fork 46
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
Do a last polling before closing the IocpProactor #44
Conversation
Get latest quamash works
Ok this pull request removes the exception of bug #38 but it's not perfect. I get the following errors after more testing, sometimes :
I guess there are some checks to do in the polling side ? |
If you could rebase this, that would be great, this should get rid of the pointless merge commit |
Ok but my fix is not ready yet. I think I'll need your help on the IOCP side. |
@aknuds1 actually wrote the IOCP code, but I'll try my best. |
@Insoleet Maybe I can help, hit me. I think first of all though, I'd like to see a test corresponding to why this fix is needed. |
This is meant to fix #38 which are all warnings Windows logs during shutdown, but don't actually prevent any functionality. |
@harvimt Thanks for the explanation. |
This simple test does raise an error when closing the loop on Windows :
The complete output is the following :
I'm not at all an expert of the Microsoft world, but our app needs to support Windows that's why I try to fix this error... Thanks for your help ! (and I love your lib by the way :) ) |
@Insoleet I guess your test could verify that there are no logged errors? Then it should fail it would seem. |
I can't catch this exception from the test because it's catched by PyQt stack (raised after a quamash signal I guess ?). The test is just a simple use case to show the problem... |
@Insoleet Can't you detect that an error has been logged? There's this log line: |
Oh you are right.
|
@Insoleet That solution was a bit different from what I initially envisioned, but if it works I think it's better since it's more direct in detecting an exception. |
Well as soon as we can reproduce the error... :) So to say it short : Also, polling seems to help solving the bug, at least in simple cases like this one. But the unit test suite of our app raise another error after forcing a polling when closing the IocpProactor :
|
You can notice that running this test never ends. Before the exception is raised, a callback is added in quamash.QEventLoop, but it is never called. The callback is supposed to call the "QEventLoop._loop_self_reading". The callback is added when canceling the overlapped future : The callback uses |
@Insoleet Do you need help figuring this out? I've got a busy day ahead of me though, so can't make any promises today at least. |
Yes, this is quite a hard bug. I'm not sure if it's because of quamash reimplementation of IocpProactor, or if it's asyncio having problems... Closing the loop freezes on this line : If you have any idea, or try to replicate my analysis by your side that'd be great... |
Oh it seems to be a compatibility problem with aiohttp. The test I suggested earlier is not freezing. But our app tests are. So I tried the following simple test : import sys
import unittest
import asyncio
import aiohttp
import logging
import quamash
from quamash import QApplication
class Bug(unittest.TestCase):
def setUp(self):
self.qapplication = QApplication([])
self.lp = quamash.QEventLoop(self.qapplication)
asyncio.set_event_loop(self.lp)
self.except_raised = False
self.lp.set_exception_handler(lambda loop, context: self.exception_handler(loop, context))
def exception_handler(self, loop, context):
self.except_raised = True
def test_bug(self):
@asyncio.coroutine
def waiting():
response = yield from aiohttp.get("http://forum.ucoin.io")
yield from response.release()
yield from asyncio.sleep(1)
self.lp.run_until_complete(waiting())
try:
self.lp.close()
finally:
asyncio.set_event_loop(None)
self.assertFalse(self.except_raised)
if __name__ == '__main__':
logging.basicConfig(stream=sys.stderr)
logging.getLogger().setLevel(logging.DEBUG)
unittest.main() Which sometimes never ends. |
Eh, nevermind, it's Windows of course. Going to see if I can bring that up. |
This is a problem with IOCP, I think it only exists on windows. On Sun, Sep 20, 2015 at 12:52 PM, Arve Knudsen notifications@github.com
|
@harvimt Yep, I noticed right after (oops). Have to refresh my Windows installation now, after not using it for a long time. |
But @Insoleet, you say that the test only sometimes hangs? Is there a way to reproduce deterministically? |
I did not find a way to provoke the bug 100% of times... But it happened really often. My appveyor tests instance were almost all freezing for example. |
I just tested with Python 3.4.0, Quamash 540ab6a, PyQt 5.4.0 and aiohttp 0.17.3 on Windows 8.1, several times. The test doesn't hang for me. |
@Insoleet, can you integrate https://github.com/Insoleet/quamash/pull/2? It fixes an exception due to polling while closing. |
Handle disposed IOCP handle while closing
Well, even after your patch, the test hangs here (Windows 7). The test hangs when we are trying to close the loop. |
@Insoleet Yes, the patch doesn't solve that, it fixes another issue. |
I think this PR can be closed thanks to @peterazmanov |
Fix bug #38