After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 638229 - onwindowcreate fails with CannotSendRequest with python2.7
onwindowcreate fails with CannotSendRequest with python2.7
Status: RESOLVED FIXED
Product: LDTP
Classification: Other
Component: ldtp2
unspecified
Other Linux
: Normal normal
: ---
Assigned To: LDTP Development Mailing List
LDTP Development Mailing List
Depends on:
Blocks:
 
 
Reported: 2010-12-28 23:37 UTC by JB Lallement
Modified: 2011-01-01 03:53 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
onwindowcreate xmlrpc verbose log (173.39 KB, text/x-log)
2010-12-29 22:07 UTC, JB Lallement
  Details
patch to close the connection on error (826 bytes, patch)
2010-12-30 00:26 UTC, JB Lallement
none Details | Review

Description JB Lallement 2010-12-28 23:37:25 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):
  • File "/usr/lib/pymodules/python2.7/ldtp/__init__.py", line 251 in run
    if not self.poll_server():
  • File "/usr/lib/pymodules/python2.7/ldtp/__init__.py", line 266 in poll_server
    event = poll_events()
  • File "/usr/lib/pymodules/python2.7/ldtp/client.py", line 51 in __call__
    return self.__send(self.__name, args)
  • File "/usr/lib/python2.7/xmlrpclib.py", line 1575 in __request
    verbose=self.__verbose
  • File "/usr/lib/pymodules/python2.7/ldtp/client.py", line 74 in request
    self, host, handler, request_body, verbose=0)
  • File "/usr/lib/python2.7/xmlrpclib.py", line 1264 in request
    return self.single_request(host, handler, request_body, verbose)
  • File "/usr/lib/python2.7/xmlrpclib.py", line 1289 in single_request
    self.send_request(h, handler, request_body)
  • File "/usr/lib/python2.7/xmlrpclib.py", line 1391 in send_request
    connection.putrequest("POST", handler, skip_accept_encoding=True)
  • File "/usr/lib/python2.7/httplib.py", line 853 in putrequest
    raise CannotSendRequest() CannotSendRequest


If you remove the last wait, the program ends before the callback being called, and obviously doesn't crash.
Comment 1 Nagappan Alagappan 2010-12-29 00:00:02 UTC
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
Comment 2 JB Lallement 2010-12-29 00:42:24 UTC
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.
Comment 3 Nagappan Alagappan 2010-12-29 21:51:42 UTC
(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
Comment 4 JB Lallement 2010-12-29 22:07:02 UTC
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
Comment 5 JB Lallement 2010-12-29 23:41:38 UTC
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.
Comment 6 Nagappan Alagappan 2010-12-30 00:11:58 UTC
(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.
Comment 7 JB Lallement 2010-12-30 00:26:01 UTC
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.
Comment 8 Nagappan Alagappan 2010-12-30 04:54:22 UTC
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
Comment 9 JB Lallement 2010-12-30 22:35:58 UTC
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.
Comment 10 Nagappan Alagappan 2011-01-01 03:53:51 UTC
Thanks for the bug report and the patch, have applied it in git head.