[issue18930] os.spawnXX functions terminates process if second argument is empty list
Stefan Schukat added the comment: @Batuhan the error does not appear anymore in at least Python 3.6.1 >>> import os >>> nPath = os.path.join(os.environ["windir"], "notepad.exe") >>> os.spawnv(os.P_NOWAIT, nPath, []) # or os.spawnv(os.P_NOWAIT, nPath, [], {}) Traceback (most recent call last): File "", line 1, in ValueError: spawnv() arg 2 cannot be empty -- ___ Python tracker <https://bugs.python.org/issue18930> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
RE: AttributeError: 'win32com.gen_py.Microsoft Excel 14.0 Object Library.Shape instance at 0x70837752' object has no attribute 'SeriesCollection'
Hello, the chartObj is not a Chart object it is a shape see win32com.gen_py.Microsoft Excel 14.0 Object Library.Shape ... Hence this object has no SeriesCollection try the Chart Attribute of the shape object. from win32com.client import Dispatch Excel = Dispatch(Excel.Application) WB = Excel.Workbooks.Add() Shape = WB.Sheets[0].Shapes.AddChart() Shape.Chart.SeriesCollection bound method CDispatch.SeriesCollection of COMObject unknown Regards Stefan Schukat -Original Message- From: Python-list [mailto:python-list-bounces+sschukat=dspace...@python.org] On Behalf Of Jaydeep Patil Sent: Thursday, February 13, 2014 12:05 PM To: python-list@python.org Subject: AttributeError: 'win32com.gen_py.Microsoft Excel 14.0 Object Library.Shape instance at 0x70837752' object has no attribute 'SeriesCollection' I have created chart object. But unable to add series into chart. Look at below collection Code: chartObj = addNewChart(newws,-4169,350,600) print chartObj; win32com.gen_py.Microsoft Excel 14.0 Object Library.Shape instance at 0x70837752 chartObj.SeriesCollection().NewSeries() Traceback (most recent call last): File pyshell#16, line 1, in module chartObj.SeriesCollection().NewSeries() File C:\Python27\lib\site-packages\win32com\client\__init__.py, line 465, in __getattr__ raise AttributeError('%s' object has no attribute '%s' % (repr(self), attr)) AttributeError: 'win32com.gen_py.Microsoft Excel 14.0 Object Library.Shape instance at 0x70837752' object has no attribute 'SeriesCollection' se = chartObj.SeriesCollection().NewSeries() Regards Jaydeep Patil -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
[issue18930] os.spawnXX functions terminates process if second argument is empty list
New submission from Stefan Schukat: If os.spawnv or os.spawnve is called with an empty second argument the process terminates in release builds under Windows. This is simple to reproduce: import os nPath = os.path.join(os.environ[windir], notepad.exe) os.spawnv(os.P_NOWAIT, nPath, []) # or os.spawnv(os.P_NOWAIT, nPath, [], {}) This has the same cause as the bug reported for execv http://bugs.python.org/issue1039 and could be fixed in the same way. -- components: Interpreter Core messages: 196988 nosy: SSchukat priority: normal severity: normal status: open title: os.spawnXX functions terminates process if second argument is empty list versions: Python 2.7 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18930 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
RE: ctypes:Multiple library access problem
Massi wrote: Hi everyone, in my script I need to execute multiple separated loading of the same dll library, in order to handle the internal variables with different threads. Consider the followin piece of code: lib1 = cdll.LoadLibrary(MyLib.dll)) lib2 = cdll.LoadLibrary(MyLib.dll)) lib1.var1 = 0 lib2.var1 = 1 Now, if I print the value of lib1.var1 I get 1, that is lib1 and lib2 point to the same memory space. Is there a way to create different instances of the same library? Or, alternatively, does it exist any workaround to avoid lib1 and lib2 share the same memory space? Thanks in advance. Windows will not load the same DLL twice into the same process in two different places. When it detects that it's the same one, it simply returns the same handle as the earlier one, without any loading or initializing. With some DLL's, you might get away with copying it to a different filename, and then loading each as an independent item. But unless you wrote it yourself, or it has been documented for that behavior, you're taking a big risk. On the other hand, if the DLL was written with threading in mind, then it'll get notified for each new thread you create, and it can manage TLS (thread local storage) rather than using extern vars. I have no idea how to get at those from Python, however. DaveA -- http://mail.python.org/mailman/listinfo/python-list The statement from Dave is as far true as the library is loaded without a path. Hence windows searches the system path and always finds the same file. If you load a DLL with an absolute path window will place the dll multiple times into the process. e.g. lib1 = cdll.LoadLibrary(rc:\temp\MyLib.dll) lib2 = cdll.LoadLibrary(rd:\temp\MyLib.dll) This has the same effect as renaming the library on the disk. Stefan -- http://mail.python.org/mailman/listinfo/python-list
AW: Python2.6 + win32com crashes with unicode bug
Hello Gerrit, there is no problem in the file, but in the description of the Visio API. The place where the error occurs is during the definition of the parameters of the corresponding Python methods. The information for the names comes from the typelibrary of visio. Probably there is a non english name inside the typelibrary (MS used native names in early Office products) which then could not decoded to a correct Python name. In my Version of Vsio OpenEx has two parameters called FileName and Flags. You have to look in your typelibrary, e.g. with OleView http://www.microsoft.com/downloads/details.aspx?familyid=5233b70d-d9b2-4cb5-aeb6-45664be858b6displaylang=en and check the parameters. Regards Stefan -Ursprüngliche Nachricht- Von: python-list-bounces+sschukat=dspace...@python.org [mailto:python-list-bounces+sschukat=dspace...@python.org] Im Auftrag von GerritM Gesendet: Freitag, 30. Oktober 2009 18:00 An: Terry Reedy Cc: python-list@python.org Betreff: Re: Python2.6 + win32com crashes with unicode bug Terry Reedy schreef: GerritM wrote: I have automated image generation with Python, win32com and Visio5.0. This works well upto Python2.5 but fails with Python 2.6. Short term solution is to return to 2.5 :-(. I have reproduced the bug below with a minimum of Python lines. Below the problem the working example from 2.5 kind regards, Gerrit ---minimal session reproducing the bug--- ..snip.. d = v.Documents.OpenEx(D:/temp/test.vsd,8) ...snip... UnicodeDecodeError: 'ascii' codec can't decode byte 0x83 in position 52: ordinal not in range(128) I suspect that 2.6 fixed the bug of allowing non-ascii chars when using the ascii codec. I would check to see if there is an 0x83 in D:/temp/test.vsd ...snip... the string D:/temp/test.vsd itself does not contain any charactervalue128: for c in D:/temp/test.vsd: print ord(c), , 68 58 47 116 101 109 112 47 116 101 115 116 46 118 115 100 (on my current Python 2.5 configuration) The presumably binary file itself may contain any value, but I don't expect Python or win32com to do anything with the file content... There are explanations on internet that Windows uses internally 2 (incompatible) API's that cause poblems with Unicode based filenames. I do something like that to be the problem in Python 2.6 kind regards, Gerrit -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: pydepend (checking dependencies like jdepend) ?
No, py2exe does not display such information but has an algorithm to collect such information. Perhaps this is a starting point for you. Stefan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Bernhard Merkle Sent: Friday, January 04, 2008 2:25 PM To: python-list@python.org Subject: Re: pydepend (checking dependencies like jdepend) ? On Jan 4, 1:57 pm, Stefan Schukat [EMAIL PROTECTED] wrote: Hi, try to look at py2exe. This module scans all dependencies to pack them into one executable. my intention is to _know_ (or display or list or whatever) the dependencies. (see also my original posting). The aim is to control and have a view on modularization and e.g. avoid unnecessary bidirectional dependencies etc. does py2.exe display such information ? Berni. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: pydepend (checking dependencies like jdepend) ?
Hi, try to look at py2exe. This module scans all dependencies to pack them into one executable. Stefan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Bernhard Merkle Sent: Friday, January 04, 2008 1:14 PM To: python-list@python.org Subject: pydepend (checking dependencies like jdepend) ? Hi there, think %Subject says all. I am wondering if there is some tool to check dependencies within python programs. (something like jdepend for python ;-) Of course the dependencies are at runtime (dynamic) and not statically +dynamically (as in Java), but anyway it would be interesting to know of them (for better modularization e.g.) TIA, Berni. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: win32com problem: more than one instance
Hello Thomas, excel registers its COM objects with REGCLS_SINGLEUSE that means one COM object is created per process. In Solidworks it seems that that they register with REGCLS_MULTIPLEUSE, which means on process can serve more than one COM object. Hence you have no chance to get multiple instances running in any COM client. Stefan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tim Golden Sent: Friday, August 31, 2007 1:36 PM To: Thomas Rademacher Cc: python-list@python.org Subject: Re: win32com problem: more than one instance Thomas Rademacher wrote: Hello, I start my script convert.py simultaneously in any dos-shells several times. But I get every time the same solidworks instance. I see in the proccess (task) manager only one solidworks.exe Therefore I get for all simultaneous conversions the same output file. I *think* -- and I'm really hoping someone more knowledgeable can chip in here -- that it's down to the particular COM object implementation. ie Excel may choose to offer you separate instances (or whatever they're called) while SolidWorks may not. TJG -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: [pywin32] - Excel COM problem
Characters is a parameterized property. So you can't call it without a generated wrapper. see inside the wrapper: # Result is of type Characters # The method GetCharacters is actually a property, but must be used as a method to correctly pass the arguments def GetCharacters(self, Start=defaultNamedOptArg, Length=defaultNamedOptArg): so in your case: xlsapp = gencache.EnsureDispatch(Excel.Application) wb = xlsapp.Workbooks.Add() sheet = wb.Sheets[0] myShape = sheet.Shapes.AddShape(1, 315, 200, 400, 300) myShape.Select() xlsapp.Selection.Characters.Text = finalText[0:200] xlsapp.Selection.GetCharacters(200).Insert(finalText[200:400]) excelfile = Hello.xls wb.SaveAs(excelfile) wb.Close() xlsapp.Quit() Stefan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Andrea Gavana Sent: Friday, February 09, 2007 9:59 PM To: python-list@python.org Subject: [pywin32] - Excel COM problem Hi All, I have a very simple python script that tries to put a rectangular shape in a worksheet and then add some text inside that shape. The main problem, is that as usual Excel doesn't like input strings longer than 200 and something characters. So, by just recording a macro in Excel, I tried to append the text in the shape by dividing it in chunks. For example, I tried this little script: #-- from win32com.client import Dispatch finalText = A*1250 xlsapp = Dispatch(Excel.Application) wb = xlsapp.Workbooks.Add() sheet = wb.Sheets[0] myShape = sheet.Shapes.AddShape(1, 315, 200, 400, 300) myShape.Select() xlsapp.Selection.Characters.Text = finalText[0:200] xlsapp.Selection.Characters(200).Insert(finalText[200:400]) excelfile = Hello.xls wb.SaveAs(excelfile) wb.Close() xlsapp.Quit() #-- And it crashes with an impossible error: Traceback (most recent call last): File D:\MyProjects\pywin32.py, line 13, in module xlsapp.Selection.Characters(200).Insert(finalText[200:400]) File C:\Python25\lib\site-packages\win32com\client\dynamic.py, line 172, in __call__ return self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_. defaultDispatchName,None) pywintypes.com_error: (-2147352573, 'Member not found.', None, None) However, the macro I recorded in Excel does exactly that: it appends chunks of the string with a maximum length of 200 chars. Am I missing something here? This is with Python 2.5, PythonWin 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win32, Windows XP SP2. Thank you for your consideration. Andrea. Imagination Is The Only Weapon In The War Against Reality. http://xoomer.virgilio.it/infinity77/ -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: PyWin32-winxptheme and py2exe
You probably need to include the common Control Manifest to supprt themes see in the py2exe\samples\advanced directory for an example how to do it. Stefan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Andrea Gavana Sent: Tuesday, November 14, 2006 10:43 PM To: python-list@python.org Subject: PyWin32-winxptheme and py2exe Hi all, I am having some troubles mixing py2exe and winxptheme. Basically, I am using wxPython 2.7.2.0 with Python 2.5, and painting some window background using the UxTheme via winxptheme. This is what I am doing: hwnd = MyWindow.GetHandle() self.hTheme = winxptheme.OpenThemeData(hwnd, Window) winxptheme.DrawThemeBackground(self.hTheme, dc.GetHDC(), 5, 1, (rc.top, rc.left, rc.right, rc.bottom), None) This works very well using python directly, but when I generate and executable file with py2exe, I get this error when executing that last line: TypeError: an integer is required This is because self.hTheme is *None*. It seems like OpenThemeData can not be initialized in an executable, or at least that I am not able to do it. Does anyone have a possible solution to this problem? I have tried all the possibilities with py2exe, meaning bundle=1, bundle=2, bundle=3, compressed=1, compressed=2, every possible combination. But it doesn't work :-( I attach my setup file, if it can be of any help. Thank you very much for every pointer. -- Andrea. Imagination Is The Only Weapon In The War Against Reality. http://xoomer.virgilio.it/infinity77/ -- http://mail.python.org/mailman/listinfo/python-list
RE: Python opening multiple thread of matlab
Hello, you just forgot to initialize the COM runtime for the separate thread. try following: def __init__(self,matlab_command): self.matlab_command = matlab_command threading.Thread.__init__(self) def run(self): import pythoncom pythoncom.CoInitialize() try: matlab_object = Dispatch('matlab.application.single') execute = getattr(matlab_object,'Execute') execute(self.matlab_command) finally: matlab_object = None pythoncom.CoUnitialize() Stefan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of tsjuan Sent: Saturday, November 11, 2006 2:56 PM To: python-list@python.org Subject: Python opening multiple thread of matlab Hello Python Users, I've been trying to run multiple thread of Matlab by calling its com object via python. However, I keep getting error message that says Python can't find the attribute of certain function that I want to execute in Matlab. I know the com function is exist, it works just fine if I don't run within thread. Below is my sample code, any helps or comments are appreciated. Thanks, Tanto import threading from win32com.client import Dispatch class MyThread ( threading.Thread ): def __init__(self,matlab_command): self.matlab_command = matlab_command self.matlab_object = Dispatch('matlab.application.single') threading.Thread.__init__(self) def run(self): execute = getattr(self.matlab_object,'Execute') execute(self.matlab_command) def awesome_dud(self): execute = getattr(self.matlab_object,'Execute') execute(self.matlab_command) a = MyThread('a=1:1:100') b = MyThread('b=1:1:200') # Running matlab function through thread (It's not working) # = a.start() b.start() a.join() b.join() # Running matlab function not through thread (it's working) # = a.awesome_dud() b.awesome_dud() -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: python thread state
For this use case the PyGILState API was introduced. e.g. try PyGILState_STATE state = PyGILState_Ensure() run python code PyGILState_Release(state) Stefan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Bryan Sent: Monday, October 23, 2006 2:32 PM To: python-list@python.org Subject: python thread state hi, i'm trying to write a multithreaded embedded python application and i'm having some trouble. i found this article embedding python in multi-threaded c/c++ applications in the python journal (http://www.linuxjournal.com/article/3641) but there still seems to be a step missing for me. each time a function in my c module is called, it's called on a different c thread. i would then like to call a function in an embedded python script. from my understanding of the article, you can associate a python script with a c thread by calling PyThreadState_New as in this code: // save main thread state PyThreadState * mainThreadState = NULL; mainThreadState = PyThreadState_Get(); PyEval_ReleaseLock(); // setup for each thread PyEval_AcquireLock(); PyInterpreterState * mainInterpreterState = mainThreadState-interp PyThreadState * myThreadState = PyThreadState_New(mainInterpreterState); PyEval_ReleaseLock(); //execute python code PyEval_AcquireLock(); PyThreadState_Swap(myThreadState); # execute python code PyThreadState_Swap(NULL); PyEval_ReleaseLock(); unfortunately, this doesn't work for me because each time i get called to execute python code, i'm in a new c thread and PyThreadState_Swap seems to want to be executed in the same c thread that PyThreadState_New was executed in. if this isn't the case, please let know. i then called PyThreadState_New each time i wanted to call a python function in the script, but PyThreadState_New wipes out, or rather gives you a new global dictionary, because i lost all my global variables. the article assumes you have one c thread per python thread state, but i want multiple c threads per python thread state. Is there a c api function that will associate a c thread without resetting the global dictionary? thank you, bryan -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: Thread termination
Hello you are using the module variable ie inside the Generic Function, but you have to use "d" since this is the Python object which is allowed to access the COM object in the separate thread. Stefan From: Tejovathi P [mailto:[EMAIL PROTECTED] Sent: Monday, October 16, 2006 9:47 AMTo: Stefan SchukatSubject: Re: Thread termination HI all, I have a problem in accesing COM objects in threads. To be precise, lets assume that I have a class GenericFunctions which is defined as follows: import win32com.client, pythoncom, thread ie=win32com.client.Dispatch('internetexplorer.application') ie.Visible=1 class GenericFunctions: def __init__(self): print "In Constructor of Generic Functions" def MyNavigate(self,dest): ie.Navigate(dest) Now there is another file Main.py which is defined as follows: import win32com.client, pythoncom, thread from GenericFunctions import *obj = GenericFunctions() class Mainclass: def __init__(self); print "In Constructor of Main class" def threadFunction(self,dest): pythoncom.CoInitialize() d=pythoncom.CoGetInterfaceAndReleaseStream(s, pythoncom.IID_IDispatch) my_ie=win32com.client.Dispatch(d) obj.func(dest) # this is gving an error. pythoncom.CoUninitialize() if __name__ == "__main__": s=pythoncom.CoMarshalInterThreadInterfaceInStream(pythoncom.IID_IDispatch,ie) thread.start_new_thread(self.nav, (s,'www.google.com ') Basically, I want to access object of GenericFunctions class inside threadFunction(). However I was able to execute my_ie.Navigate("google.com"). But that was not I wanted. I am not knowing where the error is Please let me know the solution ASAP... Teja.P On 10/13/06, Stefan Schukat [EMAIL PROTECTED] wrote: Reading from your last posts you are using COM objects. Therefore youshould not "kill" the thread since this would lead to reference leaks. So there are only two ways left:1. Program a specific interpreter and not use python.exe whichimplements an access to PyThreadState_SetAsyncExc2. Check in the separate thread at specific times a variable which is set in the main thread.Both need the try finally construct in the threadfunction to release COMobjects in the right way.I.e., (taking the source from Roger):def ThreadFunction(istream, dest): pythoncom.CoInitialize() // Initialize COM Runtime for this thread try: d=pythoncom.CoGetInterfaceAndReleaseStream(istream,pythoncom.IID_IDispatch) my_ie=win32com.client.Dispatch (d) my_ie.Navigate(dest) finally: my_ie = None// Release COM object pythoncom.CoUninitialize() // Release COM Runtime for thisthread Stefan -- http://mail.python.org/mailman/listinfo/python-list
RE: Thread termination
Reading from your last posts you are using COM objects. Therefore you should not kill the thread since this would lead to reference leaks. So there are only two ways left: 1. Program a specific interpreter and not use python.exe which implements an access to PyThreadState_SetAsyncExc 2. Check in the separate thread at specific times a variable which is set in the main thread. Both need the try finally construct in the threadfunction to release COM objects in the right way. I.e., (taking the source from Roger): def ThreadFunction(istream, dest): pythoncom.CoInitialize() // Initialize COM Runtime for this thread try: d=pythoncom.CoGetInterfaceAndReleaseStream(istream, pythoncom.IID_IDispatch) my_ie=win32com.client.Dispatch(d) my_ie.Navigate(dest) finally: my_ie = None // Release COM object pythoncom.CoUninitialize() // Release COM Runtime for this thread Stefan -- http://mail.python.org/mailman/listinfo/python-list
RE: how to use python com server in c++?
Hello, you have to use the low level API methods for access and then the methods of IDispatch since the win32com gateway only supports late bound calls for dispatch interfaces. e.g. IDispatch* pDisp; CoCreateInstance( ... CLSID_Leelay, , IID_IDispatch, ...pDisp); // Add Call without any error checking LCID lcid = LOCALE_USER_DEFAULT; OLECHAR* pwszName = _T(Add); DISPID dispid; pDispatch-GetIDsOfNames(IID_NULL, pwszName, 1, lcid, dispid); VARIANTARG vargsArgs[2]; VariantInit(vargsArgs[0]); VariantInit(vargsArgs[1]); vargsArgs[0].vt = VT_I4; vargsArgs[0].lVal = 5; vargsArgs[1].vt = VT_I4; vargsArgs[1].lVal = 8; DISPPARAMS dispparParams = {vargsArgs, 0, 1, NULL}; VARIANT varResult; VariantInit( varResult); HRESULT hr = pDispatch-Invoke(dispid, IID_NULL, lcid, DISPATCH_METHOD, dispparParams, varResult, NULL, NULL); Or use a library which has some support for late bound calls, e.g. ATL: CComQIPtrIDispatch spIDispatch; hr = spIDispatch.CoCreateInstance(CLSID_ComServer); CComDispatchDriver spSumDisp(spIDispatch); CComVariant svarcResult; CComVariant svarcParam1(5); CComVariant svarcParam2(8); spSumDisp.Invoke2(LAdd, svarcParam1, svarcParam1, svarcResult); Stefan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Leo Jay Sent: Saturday, August 19, 2006 5:23 PM To: python-list@python.org Subject: how to use python com server in c++? dear all, i have a python com server like this: import win32com.server.register class HelloWorld: _reg_clsid_ = {B0EB5AAB-0465-4D54-9CF9-04ADF7F73E4E} _reg_desc_ = 'Python test com server' _reg_progid_= Leojay.ComServer _public_methods_= ['Add', 'Mul'] def Add(self, a, b): return a+b def Mul(self, a, b): return a*b if __name__ == '__main__': win32com.server.register.UseCommandLine(HelloWorld) after registering the com server, i can use it in visual basic .net: Dim a As Integer = 5 Dim b As Integer = 8 Dim h As Object = CreateObject(Leojay.ComServer) MsgBox(h.Add(a, b).ToString() + + h.Mul(a, b).ToString()) but i don't know how to use it in visual c++. who has any idea about using this com server in viusal c++? a detailed sample of early binding would be better, thanks. -- Best Regards, Leo Jay -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: COM Makepy Question
It seems that the ocx only works in a GUI environment. Perhaps you could try to embed the ocx in a pythonwin dialog which you create invisible since the dialog is then a control container see Python24\Lib\site-packages\pythonwin\pywin\Demos\ocx\ocxtest.py Stefan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of gregarican Sent: Friday, July 07, 2006 1:37 PM To: python-list@python.org Subject: COM Makepy Question Using Pythonwin's COM Makepy utility I created a COM wrapper around an OCX file that's used to communicate with a magstripe card reader. The wrapper was created without incident and I can invoke any get type of method without a problem. But whenever I attempt to invoke any of the set type of methods I receive an error message that states: (-2147352567, 'Exception occurred.', (0, 'ctlUSBHID', 'Client Site not available', None, 1000398, -2146827890), None) Googling around I see that this error message indicates an ActiveX control that's being referenced without residing within a container. Not sure if this is something that I can fix myself within the Makepy COM wrapper or if I have to rely on the vendor shipping an updated OCX file. I did see a Python discussion thread where someone else ran into a similar problem and had to wait for the vendor to ship a revised OCX file. Dolphin Smalltalk has a similar COM wrapper utility and the same exact error occurs. The OCX file is ideally suited for Visual Basic but I don't have that compilation environment setup on my workstation to try out. Anyone familiar with such matters? I have contacted the vendor to try to initiate things on that end. But if there's something I can do to circumvent that route using Python I'd give it a go. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: embedding Python in COM server loaded with win32com
Hi, when you are running in Python the PyInitialize() is not called and therefore you don't have a valid threadstate since the call in win32com uses the standard idiom Py_BEGIN_ALLOW_THREADS() CallComServer Py_END_ALLOW_THREADS() You could use PyNewInterpreter to get a valid state, but this won't work in Python greater version 2.2, since with the new GILState API does not allow more than one interpreter per thread. You could work around the problem if you would use a localserver instead of an inproc server. With that you would always have a clean process for your server. Stefan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Fozzie Sent: Monday, June 05, 2006 3:57 PM To: python-list@python.org Subject: embedding Python in COM server loaded with win32com Hi, I have a problem which is quite circular, and hopefully either someone has encountered something similar or has a reason why this will not work. We have a COM library providing mathematics to various systems, most functions are hard-coded but we want to embed a scripting language to allow arbitrary functions to be used in the numeric engines within the library, and am using Python for this. This seems to work fine called from standalone apps, and from VB, however, Python scripts, which access the scripts via win32com.client fail in the embedding code in C++ whenever I attempt to call PyImport_AddModule. As a concrete example, consider the following minimal interface, (created using an ATL project in VC7), which has a single property, the user supplied script, and a single function 'findRoot', which in this case is nothing more than an indicator that the embedding worked, - STDMETHODIMP CMinEmbed::get_script(BSTR* pVal) { USES_CONVERSION; *pVal = SysAllocString(A2OLE(__script.c_str())); return S_OK; } STDMETHODIMP CMinEmbed::put_script(BSTR newVal) { USES_CONVERSION; __script = std::string( OLE2A( newVal)); return S_OK; } STDMETHODIMP CMinEmbed::findRoot(DOUBLE* root) { std::string progress; PyObject * main, * globals, * res, * func; try { progress = calling PyInitialize; if(!Py_IsInitialized()) Py_Initialize(); progress = get __main__ module; main = PyImport_AddModule(__main__); progress = get __main__module dictionary; globals = PyModule_GetDict(main); progress = Run the script.; res = PyRun_String(__script.c_str(), Py_file_input, globals, globals); progress = Get the function from main dictionary.; func = PyDict_GetItemString(globals, func); progress = test function, and return indicator; if(NULL != func PyCallable_Check(func)) { *root = 1.0; } else { *root = -1.0; } progress = clean up; Py_XDECREF(res); Py_Finalize(); return S_OK; } catch(...) { // SetFailString just sets the ISupportErrorInfo interface SetFailString(IID_IMinEmbed, progress.c_str()); return E_FAIL; } } - When I build my server with the above method and run it at the Python interpretor I get, from win32com.client import Dispatch s = Dispatch('minServer.MinEmbed') s.script = 'def func(x) : return x*x' s.findRoot() Traceback (most recent call last): File stdin, line 1, in ? File COMObject minServer.MinEmbed, line 2, in findRoot File i:\\Python24\lib\site-packages\win32com\client\dynamic.py, line 251, in _ApplyTypes_ result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args) pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, 'Failure to get main module', None, 0, -2147467259), None) However, works fine from VB and standalone apps. Is this approach even doable? Thanks in advance Dave Foster -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: COM Server crashing when returning large arrays
Hello Alistair, which version of pythoncom you are using? In the newer versions there is an support for a native safearray (the data type Excel is providing). In older versions the complete array was converted to a tuple which is very time and memory consuming. during this conversion you could run out of memory since you have the Python objects and the COM data in your process. I think in 207 the patch was included. Stefan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alastair Alexander Sent: Monday, May 22, 2006 6:27 PM To: python-list@python.org Subject: COM Server crashing when returning large arrays Hi ... I'm using pythoncom to create a python COM server application that needs to be able to return large arrays to COM client apps. For example, I need to be able to return an array to Excel that is 500 by 10, with each element of the array holding a 32 byte string. If I run the code for smaller arrays, say 10 by 10, it works fine. If I allow the server to try to return the entire 500 by 10 array, pythonw.exe causes a memory access violation and dies and I get an automation exception error message in the client app. I assume I'm violating some upper limit for data transfer from pythoncom into COM. Anyone know if such limitations exist? Is there a way around them? Can anyone point me in the right direction? Thanks Alastair p.s. 1st message on comp.lang.python, indeed 1st message on any news group -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: Get all attributes of a com object
Hello, you only get information about a COM object when you have a wrapper. But you are using the dynamic invoke (Dispatch). So try the typelibrary browser in Pythonwin or use the generated wrapper with makepy or gencache.EnsureDispatch. But dir will give you only the methods and internal classes. The properties you get with OBJ._prop_map_get_.keys(). Stefan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of bruno at modulix Sent: Friday, April 28, 2006 10:29 AM To: python-list@python.org Subject: Re: Get all attributes of a com object eicwo01 wrote: Thanks for your tips. But dir() and inspect did not really help. Really ? def dump(obj): for name in dir(obj): print getattr(obj, name) -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: Get all attributes of a com object
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tim Golden Sent: Friday, April 28, 2006 11:45 AM To: python-list@python.org Subject: RE: Get all attributes of a com object [snip] The only thing is that you can't always build a proxy module. I'm never quite sure why or why not. You can only build a proxy module if you have the typelibrary information which not all programs provide, since it prohibits changes in the interface the easy way. E.g., MFC application will normally not provide a typelibrary but support dynamic dispatch. Stefan -- http://mail.python.org/mailman/listinfo/python-list
RE: Help needed on COM issue
Hi, the feature you expierenced are parameterized properties. This is only supported by VB and could only be emulated in python. If you use makepy/gencache to generate a wrapper the appropriate Set methods are created: oR.SetItem(1,2, 4) Stefan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Mike Howard Sent: Wednesday, April 12, 2006 1:12 AM To: python-list@python.org Subject: Help needed on COM issue I'm doing some conversion of vb code to python code and I have a problem with a COM object Specifically in VB I can do Set oR = oA.Action debug.print oR.Item(1,2) [returns say 1] oR.Item(1,2)=4 debug.print oR [returns 4] In Python I need to do .. oR=oA.Action() print oR.Item(1,2)[0] [returns say 1] oR.Update [saves the record with the new item] But when I ty to update the value oR.Item(1,2)[0]=4 I get a TypeError : object doesn't support item assignment. I presume this is because Python is returning oR as a tupe - hence the need to refer to Item(1,2)[0] - but I can't figure out the equivalent method to update the value I need. Any help appreciated. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: win32com early binding problem
win32com does only support late bound interfaces in python scripts. To support early bound interfaces a pyd has to be created. If you want to script early bound interfaces try ctypes.com aka. comtypes from Thomas Heller. Stefan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Roland Sent: Wednesday, January 25, 2006 4:37 PM To: python-list@python.org Subject: win32com early binding problem Hello, I'm trying to use Sparx Systems Enterprise Architect OLE automation interface. There is no problem to get early binding interface using Microsoft Visual Basic. But using win32com makepy utility there problem is. Does anybody have an idea, what may disqualify python win32com from creating early binding interface? There is possibility to download trial version on considered program on www.sparxsystems.com. Thank you Roland Divin [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: Python, COM Servers, and Multi-Threading
Hi, you get best performance if you make your servers local servers, since then every interpreter runs in ist own process. If you make it an inproc server you synchronize all threads/CPUs with the GIL. Even better multithreading support you will get if you mark your server to run in an multithreaded apartment (MTA). e.g. class COMClass: _public_methods_ = [ 'Method', ... ] _reg_verprogid_ = COMServer.COMClass.1 _reg_progid_ = COMServer.COMClass _reg_desc_ = COMServer COMClass _reg_clsid_ = {30BD3490-2632-11cf-AD5B-524153480001} _reg_class_spec_ = win32com.servers.COMServer.COMClass _reg_threading_ = free # --- Threading model _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER # -- own exe Stefan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Carl Waldbieser Sent: Tuesday, October 11, 2005 12:46 AM To: python-list@python.org Subject: Python, COM Servers, and Multi-Threading I have been considering using Python and the Reportlab library for generating PDF reports for the back-end of a web based application. The application runs most of its background tasks on a dedicated server that is Windows based (Win2K or Win2k3). The program that launches the tasks requires a COM-based interface, so I wrote a Python COM server using Mark Hammond's PythonCom libraries and import and run the reporlab modules from there. I had been reading up on Python and it's handling of the multiple threads, specifically the Global Interpreter Lock (GIL). I got to wondering if a multi-processor machine machine would be able to take advantage of its extra processing power using this setup. I am guessing that the GIL is global with respect to each instance of a running Python interpreter, so if say 4 interpreters were running, a 4 processor machine would be able to take advantage of this. However, I am not quite sure how launching my reports via COM behaves-- if I launched 4 reports this way, would that be like launching 4 seperate instances of the Python interpreter, or would it be just a single instance, and therefore run into the limitations of the GIL? If so, can anybody offer suggestions as to a design that would be better able to take advantage of a multi-processor machine? Thanks, Carl Waldbieser -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: Pythoncom scripting Windows Media Player visible
Hello, you have to put the ocx in a container window (e.g. a dialog or the IE). Without this the media player just acts like a normal COM object. Example for the dialog you can find in [Pythonroot]\Lib\site-packages\pythonwin\pywin\Demos\ocx Bye Stefan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Bill Eldridge Sent: Tuesday, August 02, 2005 6:15 PM To: python-list@python.org Subject: Pythoncom scripting Windows Media Player visible I'm trying to make Windows Media Player visible and control it from Python. It seems when I call it below, I get only the console version, and there's no Visible method like with Internet Explorer. I do catch events, but I need it visible. Should it be put into a panel instead? Should a different type dispatch be called or a different method? it seems that there are a console and a windows classes in the COM browser, but I can't seem to access any useful windows classes. I get fullScreen as False, but can't set it. openPlayer(address) will launch a visible window, but with no control of the the window after that. Ideas? from win32com.client import Dispatch,DispatchWithEvents class WMPEvents: def OnVisible(self,evt): print OnVisible changed:,evt def OnError(self,evt=None): print OnError,evt def OnMediaError(self,evt=None): print OnMediaError,evt def OnDisconnect(self,evt): print OnDisconnect,evt def OnStatusChange(self): print OnStatusChange def OnDisconnect(self,evt): print Disconnect,evt def OnBuffering(self,evt): print OnBuffering changed:,evt def OnOpenStateChange(self,evt=None): print OnOpenStateChange ,evt mp = DispatchWithEvents(WMPlayer.OCX.7,WMPEvents) mp.Visible = True # Does nothing tune = mp.newMedia(C:/WINDOWS/system32/oobe/images/title.wma) mp.currentPlaylist.appendItem(tune) mp.controls.playItem(tune) mp.controls.play() raw_input(Press enter to stop playing) mp.controls.stop() -- http://mail.python.org/mailman/listinfo/python-list The Leading Manufacturing Test Company of the Year 2005 http://www.dspace.de/goto?f_s_award -- http://mail.python.org/mailman/listinfo/python-list
RE: returning list of strings from Python COM to Visual basic 6
You have to wrap the python object with a COM object: def Get_Obj(self): return win32com.server.util.wrap(an_object) Stefan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Philippe C. Martin Sent: Thursday, July 21, 2005 1:42 AM To: python-list@python.org Subject: Re: returning list of strings from Python COM to Visual basic 6 I can now pass and return quite a few types except object instances: my python code gets to the point where I do: def Get_Obj(self): . return an_object My VB code looks like Dim obj as Variant obj = acom.Get_Obj() I get an unexpected Python error . Objects of type 'instance' can not be converted to a COM VARIANT Is there a way out ? Thanks, Philippe Philippe C. Martin wrote: Hi, Is it possible ? ex: return ['1','2'] If so which type should I use in VB ? dim res as ??? Set testObj = CreateObject() res = testObj.AMethodThatReturnsAListOfStrings() Thanks, Philippe -- http://mail.python.org/mailman/listinfo/python-list The Leading Manufacturing Test Company of the Year 2005 http://www.dspace.de/goto?f_s_award -- http://mail.python.org/mailman/listinfo/python-list
RE: What are com_record objects
Use the Record Method from win32com.client object = win32com.client.Dispatch(Server.Object) IPAddress = win32com.client.Record(IPADDRESS_STRUCT, object) IPAddress.b1 = 192 IPAddress.b2 = 168 IPAddress.b3 = 0 IPAddress.b4 = 1 object.connect(IPAddress) Stefan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Gijs Korremans Sent: Wednesday, May 18, 2005 3:48 PM To: python-list@python.org Subject: What are com_record objects Hi, I want to connect to a com object with win32.client. Through this com object a have to connect to an other device with object.Connect(struct IPADDRESS_STRUCT * ip) the struct IPADDRESS_STRUCT looks like this: Byte Offset NameTypeLength (Bytes) Description 0 b1 BYTE1 Byte 1 of an internet address 1 b2 BYTE1 Byte 2 of an internet address 2 b3 BYTE1 Byte 3 of an internet address 3 b4 BYTE1 Byte 4 of an internet address Because Python doesn't have structs like C, I tried to do it with a class (C structs are classes with no private) and with pack but I always get the error message Only com_record objects can be used as records I'm new in the python language but I couldn't find anything about structs or com_records in python on the internet. Does anyone know how to do this? Kind regards, Gijs -- This message has been scanned for viruses and dangerous content by Network Sentry, and is believed to be clean. http://www.networksentry.co.za -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: how to pass an array to a VB array via COM
A patch is available at sourceforge: https://sourceforge.net/tracker/index.php?func=detailaid=1195096group_id=78018atid=551956. Stefan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of jelle Sent: Friday, April 29, 2005 4:56 PM To: python-list@python.org Subject: Re: how to pass an array to a VB array via COM Hi Stefan, Thanks for your insightful and in-depth response! Wonderful to hear that a solution is in the works, that's absolutely wonderful news. If I can help you out beta-testing the PySafeArray implementation, I'd be delighted to do so. Thanks again, Jelle. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: COM connection point
Just use obj = win32com.client.Dispatch(obj) Stefan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Oy Politics Sent: Wednesday, March 16, 2005 11:51 PM To: python-list@python.org Subject: COM connection point Hello: I am building a COM client, with the ability to be called back by events. The events can arrive independently from the server. The client method is called at the right time, so that is working. However, one parameter is itself a COM object, and I am having trouble with accessing the properties of the parameter object. Here is the output of what I have currently. -- Python execute -- event! PyIDispatch at 0x7fb134 with obj at 0x403404 event! PyIDispatch at 0x7fbbf4 with obj at 0x403404 event! PyIDispatch at 0x7a6d24 with obj at 0x403404 etc. Obj is supposed to be my intended parameter. However, when I try to access its property, I get the following: -- Python execute -- pythoncom error: Python error invoking COM method. Traceback (most recent call last): File C:\PYTHON23\Lib\site-packages\win32com\server\policy.py, line 283, in _Invoke_ return self._invoke_(dispid, lcid, wFlags, args) File C:\PYTHON23\Lib\site-packages\win32com\server\policy.py, line 288, in _invoke_ return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, None) File C:\PYTHON23\Lib\site-packages\win32com\server\policy.py, line 581, in _invokeex_ return func(*args) File E:\otsl\testprojects_folder\pythoncom\pyclihh2.py, line 26, in OnMyEvent print event!, obj, obj.AProp exceptions.AttributeError: 'PyIDispatch' object has no attribute 'AProp' QueryInterface with the target IID gives the following: exceptions.TypeError: There is no interface object registered that supports this IID CastTo gives this error: exceptions.ValueError: This object can not be cast Thanks a lot, -OY -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: keeping a COM server alive
Hi, there is no real solution if you are using a standard local server. The server is as a COM object reference counted. So if the reference count reaches 0 (no client) it will shutdown itself which is done by design. If you want a different behavior you should write either a service which exports COM objects and is started by the operating system or a Python script which you start by hand, registers the class factories and then does not shut down. Stefan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED] Sent: Monday, February 14, 2005 12:53 PM To: python-list@python.org Subject: keeping a COM server alive I have implemented a local COM Server with win32com framework where all clients use the same global object (test_obj). So far it works, but when the last client is closed the gobal object is deleted because the pythonw.exe is closed. When I create a new client a new pythonw process is started. I need that the new client gets the same global object. How can I prevent the Python COM enviornment (pythonw.exe) to close when no client exist. I figured out a workaround, but there must be real solution to the problem. The code looks like: class test: ... test_obj=test() class test_F: _reg_clsid_ = ... _reg_progid_ = test.cl _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER _public_methods_ = ... def __init__(self): self.delegate=test_obj ... Workaround to keep the local server alive if not __name__=='__main__': import win32com.client dummy=win32com.client.Dispatch(test.cl) ## if __name__=='__main__': import win32com.server.register win32com.server.register.UseCommandLine(test_F, debug=0) -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: threading and internet explorer com
... and pythoncom.CoUninitialize() My preferred way is: def run(): pythoncom.CoInitialize() try: ie = win32com.client.Dispatch('InternetExplorer.Application.1') finally: # Trigger the release of the object since after CoUninitialize # it could not be reached ie = None pythoncom.CoUninitialize() Stefan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Roger Upole Sent: Friday, January 28, 2005 7:29 AM To: python-list@python.org Subject: Re: threading and internet explorer com You'll need to call pythoncom.CoInitialize() in each thread. Roger James [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] hi, i'm using python 2.4 with pywin32... I've tried to use internet explorer control with a class. it was fine until i decided to inherit thread for the class... class domain01(threading.Thread): def __init__(self): #blabla threading.Thread.__init__(self) def run(self): self.ie = win32com.client.Dispatch('InternetExplorer.Application.1') #this line gives error if i use .start(), but if i use .run.. no error... self.ie.Visibble = 1 print running xyz = domain() xyz.start() === this is what i get: Exception in thread Thread-23: Traceback (most recent call last): File C:\Python24\lib\threading.py, line 442, in __bootstrap self.run() File C:\python2exe\domain01.py, line 41, in run self.dologin() File C:\python2exe\domain01.py, line 56, in dologin self.ie=win32com.client.Dispatch('InternetExplorer.Application.1') File C:\Python24\Lib\site-packages\win32com\client\__init__.py, line 95, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File C:\Python24\Lib\site-packages\win32com\client\dynamic.py, line 91, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File C:\Python24\Lib\site-packages\win32com\client\dynamic.py, line 79, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) com_error: (-2147221008, 'CoInitialize has not been called.', None, None) = but if i run: xyz = domain() xyz.run() ##no error! it's weird anyone know how to solve this problem? thank you :) best regards, James == Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News== http://www.newsfeeds.com The #1 Newsgroup Service in the World! 100,000 Newsgroups ---= East/West-Coast Server Farms - Total Privacy via Encryption =--- -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list