Len Remmerswaal schrieb:
> Hi,
>
> I am stumped by these error messages.
> I have created an event receiver through comtypes.client.GetEvents and
> the event routines are called and work,
> but in the mean time messages like this are generated:
>
> Event PLCSimStateChanged(<comtypes.client._events.EventReceiver object
> at 0x01E7CF90>, 31758856, u'STOP')
> Traceback (most recent call last):
> File "\loewis\25\python\Modules\_ctypes\callbacks.c", line 216, in
> 'converting callback result'
> TypeError: int expected instead of NoneType instance
> Exception in <bound method EventReceiver.handler of
> <comtypes.client._events.EventReceiver object at 0x01E7CF90>> ignored
>
> The first two lines are regular output from ShowEvents, which I have
> running as well, the other ones (" File ....") are error message.
> The corrsponding event function looks like this:
>
> def PLCSimStateChanged(self, this, NewState):
> self.logger.log("Event: PLCSimStateChanged: %s\n" % NewState)
> return 0
>
> for a template from GetModule like this:
>
> COMMETHOD([helpstring(u'Fired when a new PLC switch state is
> detected.')], HRESULT, 'PLCSimStateChanged',
> ( [], BSTR, 'NewState' )),
>
> There are two more observations:
> - The address in "<bound method EventReceiver.handler of
> <comtypes.client._events.EventReceiver object at 0x01E7CF90>>" does is
> reported equal for another event in the same event receiver.
This is expected. The events handlers are methods of the same
comtypes.client._events.EventReceiver instance.
> - I tried varying the event function a little (returning 1, returning
> None). When returning None, the messages get to look like this:
>
> Traceback (most recent call last):
> File "\loewis\25\python\Modules\_ctypes\callbacks.c", line 216, in
> 'converting callback result'
> TypeError: int expected instead of NoneType instance
> Exception in <bound method PlcSimEvents.PLCSimStateChanged of
> <__main__.PlcSimEvents instance at 0x01E873C8>> ignored
> Event PLCSimStateChanged(<comtypes.client._events.EventReceiver object
> at 0x01E7BF90>, 31758856, u'STOP')
> Traceback (most recent call last):
> File "\loewis\25\python\Modules\_ctypes\callbacks.c", line 216, in
> 'converting callback result'
> TypeError: int expected instead of NoneType instance
> Exception in <bound method EventReceiver.handler of
> <comtypes.client._events.EventReceiver object at 0x01E7BF90>> ignored
>
> i.e. the same trailer, but a header is being added.
>
> Anyone have any idea what to do about this?
I assume the event is handled by TWO receivers: The first is the one
created by ShowEvents(), the second one is your object that has the
PLCSimStateChanged method you quoted above.
Returning 0 from the PLCSimStateChanged method is correct (the return
value is a HRESULT which is a 32-bit integer value, 0 is S_OK which
means everything worked). In this case, only the method in the event
handler of ShowEvents raised the exception; in the second case where you
returned 'None' two exceptions are raised.
Looking at the code it seems that some code in the comtypes.client._events
module is buggy: can you please change line 164 from this code:
mth = getattr(sink, name, lambda self, this, *args: None)
to this code:
mth = getattr(sink, name, lambda self, this, *args: 0)
and try again?
Thomas
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
comtypes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/comtypes-users