classification
Title: test_issue_8959_b fails when run from a service
Type: Stage:
Components: ctypes, Windows Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: theller Nosy List: BreamoreBoy, amaury.forgeotdarc, brian.curtin, ocean-city, pmoore, theller, tim.golden
Priority: normal Keywords: buildbot

Created on 2010-06-21 22:39 by pmoore, last changed 2014-07-09 07:57 by pmoore. This issue is now closed.

Messages (12)
msg108328 - (view) Author: Paul Moore (pmoore) * Date: 2010-06-21 22:39
test_issue_8959_b fails when run from a service (in this case, from a buildslave running as a service).

It appears to count the number of open windows, expecting a non-zero value. But when run as a service, it looks like the return count is (correctly) zero.

FAIL: test_issue_8959_b (ctypes.test.test_callbacks.SampleCallbacksTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
 File "C:\buildslave\trunk.moore-windows\build\lib\ctypes\test\test_callbacks.py",
line 208, in test_issue_8959_b
   self.assertFalse(windowCount == 0)
AssertionError: True is not False
msg108394 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-06-22 15:41
To test windows callbacks, I suggest to use EnumResourceTypes() instead, which is more likely to work in any condition:

def test():
    from ctypes.wintypes import BOOL, HMODULE, LONG, LPARAM
    import ctypes
    EnumResourceTypes = ctypes.windll.kernel32.EnumResourceTypesA
    EnumResTypeProc = ctypes.WINFUNCTYPE(
        BOOL, HMODULE, LONG, LPARAM)

    resource_types = []
    def callback(hModule, typeid, lParam):
        resource_types.append(typeid)
        return True # keep enumerating

    hModule = None   # Main executable
    RT_MANIFEST = 24 # from winuser.h
    EnumResourceTypes(hModule, EnumResTypeProc(callback), None)

    assert RT_MANIFEST in resource_types
msg108412 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2010-06-22 19:27
> To test windows callbacks, I suggest to use EnumResourceTypes()
> instead, which is more likely to work in any condition:

Unfortunately the proposed test doesn't detect the problem in Python2.7 rc1.
It runs without crashing, even if enumerating the resources in shell32.dll
which contains a lot more stuff than python.exe.

Maybe we should just remove the 'self.assertFalse()' call
in the current test?
msg112816 - (view) Author: Paul Moore (pmoore) * Date: 2010-08-04 14:54
I'm not sure what needs to be done to move this forward, but as it's a problem with the test rather than with any actual code, could something be done to avoid masking real issues? I agree with Thomas that in the absence of any other solution, the assertFalse call should be removed pending a better answer.

I can produce a patch, but it's pretty trivial and I'm away from my development PC for a few days, so it'll be a while before I get to it.
msg113607 - (view) Author: Tim Golden (tim.golden) * (Python committer) Date: 2010-08-11 16:00
In the interests of moving this forward, I've committed the one-line removal of the assertion in r83948. Hopefully that will bring this buildbot back to life.
msg113673 - (view) Author: Tim Golden (tim.golden) * (Python committer) Date: 2010-08-12 12:23
Fudge-fix committed as r83948, r83958. Not sure what status to set
msg113675 - (view) Author: Paul Moore (pmoore) * Date: 2010-08-12 12:42
Certainly the 2.7 branch on my buildbot is now OK (3.x is failing for
other reasons :-()
msg118348 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2010-10-11 10:07
Hello. I've been finding the way to determine whether
the process is running as service or not. Does this way
work? On my environment, True is returned. I hope False
will be returned in service environment.

http://msdn.microsoft.com/en-us/library/d56de412%28v=VS.80%29.aspx
http://msdn.microsoft.com/en-us/library/ms683225%28VS.85%29.aspx

/////////////////////////////////////////

from __future__ import print_function
import ctypes
from ctypes.wintypes import *

UOI_FLAGS = 1
WSF_VISIBLE = 0x0001

class USEROBJECTFLAGS(ctypes.Structure):
    _fields_ = [("fInherit", BOOL),
                ("fReserved", BOOL),
                ("dwFlags", DWORD)]

def window_station_has_display_surfaces():
    dll = ctypes.windll.user32
    h = dll.GetProcessWindowStation()
    if not h:
        raise ctypes.WinError()
    uof = USEROBJECTFLAGS()
    needed = DWORD()
    res = dll.GetUserObjectInformationW(h,
        UOI_FLAGS, 
        ctypes.byref(uof),
        ctypes.sizeof(uof),
        ctypes.byref(needed))
    if not res:
        raise ctypes.WinError()
    return bool(uof.dwFlags & WSF_VISIBLE)

def main():
    print(window_station_has_display_surfaces())

if __name__ == '__main__':
    main()
msg118349 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2010-10-11 10:10
Oh, I forgot to mention this. I think it can be possible
to disable "gui" resource on regrtest.py when this function
returns False. (I hope #9931 also can be fixed by this)
msg118350 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2010-10-11 10:12
I'm planning to try it on buildbot XP-5.
msg118351 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2010-10-11 10:52
I confirmed window_station_has_display_surfaces() returned False
on XP-5 which is running as service.

See
http://www.python.org/dev/buildbot/builders/x86%20XP-5%203.x/builds/1453/steps/test/logs/stdio
(It ran r85362)
msg222605 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-07-09 07:36
I think this can be closed as fixed/resolved, am I correct?
History
Date User Action Args
2014-07-09 07:57:33pmooresetstatus: open -> closed
resolution: fixed
2014-07-09 07:36:42BreamoreBoysetnosy: + BreamoreBoy
messages: + msg222605
2010-11-04 13:44:30ocean-cityunlinkissue9931 dependencies
2010-10-11 10:52:54ocean-citysetmessages: + msg118351
2010-10-11 10:49:00ocean-citylinkissue9931 dependencies
2010-10-11 10:12:27ocean-citysetmessages: + msg118350
2010-10-11 10:10:37ocean-citysetmessages: + msg118349
2010-10-11 10:07:39ocean-citysetnosy: + ocean-city
messages: + msg118348
2010-08-12 12:42:33pmooresetstatus: pending -> open

messages: + msg113675
2010-08-12 12:23:32tim.goldensetstatus: open -> pending

messages: + msg113673
2010-08-11 16:00:57tim.goldensetmessages: + msg113607
2010-08-04 15:00:06pitrousetnosy: + tim.golden, brian.curtin
components: + Windows
2010-08-04 14:54:21pmooresetmessages: + msg112816
2010-06-22 19:27:58thellersetmessages: + msg108412
2010-06-22 15:41:57amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg108394
2010-06-21 22:39:27pmoorecreate