I am trying to create one to create a function in python 3.4 which will ping a server, Need to work on Windows (possibly XP and above)
I have found that I can use the WMI Win32_PingStatus () class to ping a server and the following function is written:
import sys if sys.platform .startswith ('Win32'): import WMI import pythoncom def ping (ip_address): "" if sysplatform.startswith ('win32') "can check if ping ip address check the OS ping tool" : Try: pythoncom.CoInitialize () c = wmi.WMI () status_code = c.Win32_PingStatus (address = ip_address) [0] .StatusCode if status_code == 0: Success = Anyone else is true: successful = false pythoncom. CoUninitialize () except wmi.x_wmi: # so WMI ping fails to come back and pass some: NotImplementedError if successful lifting __name__ == "__main__": Ping ("127.0.0.1")
As intended for this purpose It returns true when you can ping the IP works and liars when you can not, however every time I run it I finally get a series of errors:
Win32 Exception 0x03140980 IUnknown released on Win32 Exception 0x031635d0 IUnknown released on Win32 Exception 0x03163560 IUnknown released
Every time I run the script, although the first 2 bytes of the address change every time, the last 2 bytes always remain the same.
I have tried to comment on different sections of code and I have come to know that if I delete pythoncom.CoUninitialize ()
then exceptions do not occur. I am using pythoncom.CoInitialize ()
and pythoncom.CoUninitialize ()
as I want to call function in a formula as described
I have tried to see the print (pythoncom._GetInterfaceCount ())
to see how many interfaces are present and it has been seen that each time the interface interfaces 6 and then sometimes increases but Often not less, but they do not reduce <10 p>
Do anyone know why this exception is happening And what is it the right way?
Thanks
I think I'm able to fix the problem . It seems that you should only call pythoncom.CoInitialize ()
in a separate thread, as the caller automatically calls the main thread.
pythoncom.coinInitialize ()
.
Comments
Post a Comment