donc j'ai essayé d'ifnd un moyen d'accéder au gestionnaire de tâches. J'ai essayé quelques méthodes comprenant le module de wmi et la liste de tâche de fenêtres mais aucun ne convient à mon besoin. wmi est beaucoup trop lent et tasklist devient trop lent quand j'y accède plusieurs fois simultanément dans quelque chose en utilisant le multitraitement. donc j'ai trouvé ce script qui marche plutôt bien mais je n'arrive pas à le faire fonctionner avec le threading.pourquoi ce script ne fonctionne pas avec threading python
import win32com.client
strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("Select * from Win32_Process")
for objItem in colItems:
print "Name: ", objItem.Name
print "File location: ", objItem.ExecutablePath
ceci est l'erreur:
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Python27\lib\threading.py", line 810, in __bootstrap_inner
self.run()
File "C:\Python27\lib\threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "C:\python practice\stuff.py", line 5, in idk
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
File "C:\Python27\lib\site-packages\pypiwin32-219-py2.7-win32.egg\win32com\cli
ent\__init__.py", line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,c
lsctx)
File "C:\Python27\lib\site-packages\pypiwin32-219-py2.7-win32.egg\win32com\cli
ent\dynamic.py", line 114, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Python27\lib\site-packages\pypiwin32-219-py2.7-win32.egg\win32com\cli
ent\dynamic.py", line 91, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.II
D_IDispatch)
com_error: (-2147221008, 'CoInitialize has not been called.', None, None)
double possible de [ Utiliser win32com avec multithreading] (http://stackoverflow.com/questi ons/26764978/using-win32com-avec-multithreading) –