GNOME Bugzilla – Bug 638229
onwindowcreate fails with CannotSendRequest with python2.7
Last modified: 2011-01-01 03:53:51 UTC
ldtp from git. The following example fails with CannotSendRequest and the callbackis never executed: ----8<--------8<--------8<---- #!/usr/bin/python import ldtp, ooldtp def cb(*data): print "=== in dlgAuthenticate" ldtp.waittillguiexist('dlgAuthenticate') for arg in data: print arg ldtp.launchapp('time-admin') ldtp.waittillguiexist('dlgTimeandDateSettings') ldtp.wait(1) ldtp.onwindowcreate('dlgAuthenticate', cb, 'SuperSecretPassword') print "=== clicking btn2" ldtp.click('dlgTimeandDateSettings', 'btn2') print "=== btn2 clicked" ldtp.wait(2) ---->8-------->8-------->8---- With the backtrace: Traceback (most recent call last):
+ Trace 225299
if not self.poll_server():
event = poll_events()
return self.__send(self.__name, args)
verbose=self.__verbose
self, host, handler, request_body, verbose=0)
return self.single_request(host, handler, request_body, verbose)
self.send_request(h, handler, request_body)
connection.putrequest("POST", handler, skip_accept_encoding=True)
raise CannotSendRequest() CannotSendRequest
If you remove the last wait, the program ends before the callback being called, and obviously doesn't crash.
I modified the code to work with gedit and it works fine ! #!/usr/bin/python import ldtp, ooldtp def cb(*data): print "=== in dlgAuthenticate" ldtp.waittillguiexist('dlgFind') for arg in data: print arg ldtp.launchapp('gedit') ldtp.waittillguiexist('*-gedit') ldtp.wait(1) ldtp.onwindowcreate('dlgFind', cb, 'SuperSecretPassword') print "=== clicking btn2" ldtp.click('*-gedit', 'btnFind') print "=== btn2 clicked" ldtp.wait(2) console output: nags@nagappan-laptop:/tmp$ python test.py ** (-c:6223): WARNING **: Trying to register gtype 'WnckWindowState' as enum when in fact it is of type 'GFlags' ** (-c:6223): WARNING **: Trying to register gtype 'WnckWindowActions' as enum when in fact it is of type 'GFlags' ** (-c:6223): WARNING **: Trying to register gtype 'WnckWindowMoveResizeMask' as enum when in fact it is of type 'GFlags' GTK Accessibility Module initialized === clicking btn2 === btn2 clicked === in dlgAuthenticate SuperSecretPassword
This looks like a problem with python 2.7. The exact same script works with python 2.6. Now I haven't investigated enough to know if the problem comes from python itself or ldtp.
(In reply to comment #2) > This looks like a problem with python 2.7. With which distribution are you trying this ? Let me also try to reproduce this issue. Thanks
Created attachment 177223 [details] onwindowcreate xmlrpc verbose log ubuntu Natty (11.04) I've dig a bit further. When there is a callback registered there is the following xmlrpc sequence: - method call1 - send1 - reply1 - method call2 - send2 <-- Note no reply - callback - send/reply - method call3 - send3 - reply3 - reply2 This works with python2.6 but in python2.7 it raises a CannotSendRequest because I guess we try to send another request on the same connection before we received the reply of the previous call. I've attached the log with xmlrpc verbose mode enabled for python2.7
I've narrowed down the problem a bit. That's because xmlrpclib python2.7 now supports the keepalive feature of http/1.1 and reuses the connection in make_connection(...) When I comment out the code to reuse the connection in xmlrpclib.py, the test above passes.
(In reply to comment #5) > I've narrowed down the problem a bit. That's because xmlrpclib python2.7 now > supports the keepalive feature of http/1.1 and reuses the connection in > make_connection(...) > > When I comment out the code to reuse the connection in xmlrpclib.py, the test > above passes. I think in that case, there should be an option to explicitly set that option to False, maybe we have to explore more ! I'm currently installing natty on a VM.
Created attachment 177230 [details] [review] patch to close the connection on error Here is a proposal of a patch to close the connection on error and retry with a new one. I don't know the code of ldtp well enough to know if there is any side effect in doing this and will follow any advice.
The gedit scripts works fine in Ubuntu 11.04 as well ! Moreover I checked, the "Connection: Keep-Alive" not set in LDTP2. http://stackoverflow.com/questions/776631/using-twisteds-twisted-web-classes-how-do-i-flush-my-outgoing-buffers Also the verbose log you have uploaded doesn't have the above header info, so I guess the issue is some where else. Now the question is, are you seeing the issue with your application in natty and/or with gedit ? Thanks
I see the error with my example, the gedit example, the onwindowcreate example from the ldtp doc and any other test which calls onwindowcreate. The error is triggered even with the most simple test: ====== import ldtp def cb(): print "=== in callback" ldtp.onwindowcreate('frmCalculator', cb) ldtp.wait(5) ====== It crashes on the first call to poll_events() after onwindowcreate() If you try with python2.6, then the callback is set correctly and called when gcalctool is launched manually. I can reproduce in a fresh natty setup with the following recipe: - Download latest Natty ISO: $ zsync http://cdimage.ubuntu.com/daily-live/current/natty-desktop-i386.iso.zsync - Install Natty in a VBox VM. - Enable accessibility and logout/login - Create a working directories $ mkdir /tmp/ldtp; cd /tmp/ldtp - checkout ltdpv2 source: $ git clone git://anongit.freedesktop.org/git/ldtp/ldtp2.git - Set PYTHONPATH and enable debug output: $ export PYTHONPATH=/tmp/ldtp/ldtp2 $ export LDTP_DEBUG=1 - Copy the gedit script above to /tmp/ldtp/test_gedit.py - execute it with: $ python ./test_gedit.py Result: same failure. I've also packaged and installed the version from git and same error. Tell me if you need more information or tests from me. Thanks.
Thanks for the bug report and the patch, have applied it in git head.