From matteo.boscolo at boscolini.eu Wed Dec 7 08:08:43 2011 From: matteo.boscolo at boscolini.eu (Matteo Boscolo) Date: Wed, 07 Dec 2011 08:08:43 +0100 Subject: [python-win32] Loose com pointer Message-ID: <4EDF10FB.5080705@boscolini.eu> Hi all, I need some help or idea to a com problem.. I got this class: class foo(object): def setComObject(comObject): self.comO=comObject #This is a com object from a cad application def showForm(self) # use the self.comO to read some information from the cad application # Show the pyqt form as child of cad application # do somthing with the form # do somthing with the self.comO <----- Here if pass some time I'm not able to call any method to the com object a=foo() o="get istance of a cad application via com" a.setComObject(o) a.showForm() #<---- here if pass some time I'm not able to call any method to the com object but I I' re call the a.setComObject(o) #Faster and I take less the 30 seconds on the form object it works well It seems a problem of the garbage collector .. but I'm not sure how to debug it .. any help is really appreciated.. it's the last dangerous bug in our application ... Regards, Matteo From rickmmmbra at gmail.com Thu Dec 8 08:34:36 2011 From: rickmmmbra at gmail.com (Rikus de Milander) Date: Thu, 8 Dec 2011 09:34:36 +0200 Subject: [python-win32] Excel graphs and saving excel workbook .xls Message-ID: Hey, I am currently working on a python script to fetch data from a database and populate a excel sheet and draw some graphs. Currently I have only been able to generate a scatter graph with chart.ChartType = constants.xlXYScatter . Is there a way that one can set the position of the graph on the excel sheet or the size of the graph ? Is there maybe a option to draw a bar graph or line graph ? Another problem that I have is when saving the .xls workbook. When I use self.workbook.save(filename) [I created a object of type workbook] it does save but it also seems to close the application and remove it from the memory so then any actions after the save for eg, adding a worksheet does not work. Is there maybe a way to save the workbook without closing it ? Regards Rikus -------------- next part -------------- An HTML attachment was scrubbed... URL: From rodperson at rodperson.com Thu Dec 8 13:30:22 2011 From: rodperson at rodperson.com (Rod Person) Date: Thu, 8 Dec 2011 07:30:22 -0500 Subject: [python-win32] Excel graphs and saving excel workbook .xls In-Reply-To: References: Message-ID: <20111208073022.00005015@unknown> On Thu, 8 Dec 2011 09:34:36 +0200 Rikus de Milander wrote: > Hey, > I am currently working on a python script to fetch data from a > database and populate a excel sheet and draw some graphs. Currently I > have only been able to generate a scatter graph with chart.ChartType > = constants.xlXYScatter . Is there a way that one can set the > position of the graph on the excel sheet or the size of the graph ? > Is there maybe a option to draw a bar graph or line graph ? > > Another problem that I have is when saving the .xls workbook. When I > use self.workbook.save(filename) [I created a object of type > workbook] it does save but it also seems to close the application and > remove it from the memory so then any actions after the save for eg, > adding a worksheet does not work. Is there maybe a way to save the > workbook without closing it ? > > Regards > Rikus Can't help with the graph as I don't use them, sorry. But you should be able to use self.workbook.SaveAs(filename) this does not close excel, at least for me. -- Rod Person http://www.rodperson.com rodperson at rodperson.com "Silence is a fence around wisdom" From caesar at inmail24.com Sat Dec 10 15:52:50 2011 From: caesar at inmail24.com (Cesar Romani) Date: Sat, 10 Dec 2011 09:52:50 -0500 Subject: [python-win32] pywintypes.com_error Message-ID: What's wrong with the following code? -------------------- from win32com.shell import shell import pythoncom, os class PyShortcut: def __init__(self): self._base = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink) def load(self, filename): self._base.QueryInterface(pythoncom.IID_IPersistFile).Load(filename) def save(self, filename): self._base.QueryInterface(pythoncom.IID_IPersistFile).Save(filename, 0) def __getattr__(self, name): if name != "_base": return getattr(self._base, name) if __name__=='__main__': import sys shortcut = PyShortcut() if len(sys.argv) > 1 and os.path.exists(sys.argv[1]): shortcut.load(sys.argv[1]) print '''Shortcut in file %s to file:\n\t%s\nArguments:\n\t%s\nDescription:\n\t%s\nWorking Directory:\n\t%s'''%( file, shortcut.GetPath(shell.SLGP_UNCPRIORITY)[0], shortcut.GetArguments(), shortcut.GetDescription(), shortcut.GetWorkingDirectory() ) -------------------- If I try to use it, as in: python shortcut.py test.c I get: -------------------- Traceback (most recent call last): File "shortcut.py", line 22, in shortcut.load(sys.argv[1]) File "shortcut.py", line 10, in load self._base.QueryInterface(pythoncom.IID_IPersistFile).Load(filename) pywintypes.com_error: (-2147467259, 'Unspecified error', None, None) -------------------- I'm using python 2.7 on Windows 7 Home Premium with pywin32-216.win32-py2.7 Many thanks in advance, -- Cesar From boctom at hotmail.com Mon Dec 12 19:42:19 2011 From: boctom at hotmail.com (Boc Tom) Date: Mon, 12 Dec 2011 18:42:19 +0000 Subject: [python-win32] makepy.py usage and COM Message-ID: Hi, I have Python 3.2.2 and pyWin32 build 216 : I have the same issue already mentionned here : http://mail.python.org/pipermail/python-win32/2008-August/008093.html I just can't get the code right, Is there any update that would fix that bug ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From boctom at hotmail.com Mon Dec 12 19:56:26 2011 From: boctom at hotmail.com (Boc Tom) Date: Mon, 12 Dec 2011 18:56:26 +0000 Subject: [python-win32] JavaScript - Python Message-ID: Hi, I want to use Python to automate InDesign, There is very little help on that subject ! I would like to use some of the sample scripts provided in the InDesign Sripting documentation, So I translate them from VBScript to Python which is ok except there are some parts written in JavaScript as well : Quote from the tutorial "Importing a graphic" : """ VBScript does not have the ability to do this, so we'll use a JavaScript to get a file name. We'll run the JavaScript using InDesign's DoScript feature. myJavaScriptString = "var myTextFile = File.openDialog(""Choose a graphicfile"");myTextFile.fsName;" Run the JavaScript using DoScript. myGraphicFileName = myInDesign.DoScript(myJavaScriptString, idScriptLanguage.idJavascript) """ So my question would be : - how to import a graphic into Indesign using Python Win32 ? - Should I try to make the doScript command work, the following command doesn't work : myGraphicFileName = myInDesign.DoScript(myJavaScriptString, language = Javascript) Thanks for your help, Regards, Thomas -------------- next part -------------- An HTML attachment was scrubbed... URL: From pfraser at spatialmedia.com Tue Dec 13 03:22:33 2011 From: pfraser at spatialmedia.com (Peter Fraser) Date: Tue, 13 Dec 2011 15:22:33 +1300 Subject: [python-win32] win32com and the GIL Message-ID: <4EE6B6E9.1040107@spatialmedia.com> Hello Can win32com be made to release the GIL when it calls into COM components? Presumably it doesn't do this by default . I'm calling an apartment threaded COM component (VB6) and NOT passing any Python objects to that component (I promise). thankyou and have a splendid day Peter From boctom at hotmail.com Wed Dec 14 18:42:50 2011 From: boctom at hotmail.com (Boc Tom) Date: Wed, 14 Dec 2011 17:42:50 +0000 Subject: [python-win32] COM Browser Adobe InDesign Type Library not loading Message-ID: Hi, Using PythonWin with InDesign, "The type info can not be loaded " when browsing the Adobe Type Library, Any idea how to fix this ? Thanks for your help, Thomas -------------- next part -------------- An HTML attachment was scrubbed... URL: From admin at mbnoimi.net Thu Dec 15 10:48:15 2011 From: admin at mbnoimi.net (Muhammad Bashir Al-Noimi) Date: Thu, 15 Dec 2011 11:48:15 +0200 Subject: [python-win32] Unable to build .msi package for pywin32 Message-ID: <4EE9C25F.1070802@mbnoimi.net> An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: build.log.bz2 Type: application/octet-stream Size: 19926 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: admin.vcf Type: text/x-vcard Size: 331 bytes Desc: not available URL: From skippy.hammond at gmail.com Fri Dec 16 04:42:43 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Fri, 16 Dec 2011 14:42:43 +1100 Subject: [python-win32] win32com and the GIL In-Reply-To: <4EE6B6E9.1040107@spatialmedia.com> References: <4EE6B6E9.1040107@spatialmedia.com> Message-ID: <4EEABE33.70801@gmail.com> On 13/12/2011 1:22 PM, Peter Fraser wrote: > Hello > > Can win32com be made to release the GIL when it calls into COM > components? Presumably it doesn't do this by default . It does do it by default and there is no way to have it *not* do it. > I'm calling an apartment threaded COM component (VB6) and NOT passing > any Python objects to that component (I promise). Assuming you mean you aren't passing a COM object that happens to be implemented in Python, then it doesn't matter if you do - the GIL will be re-grabbed when necessary. Cheers, Mark > > > thankyou and have a splendid day > > Peter > > > > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 From skippy.hammond at gmail.com Fri Dec 16 04:44:33 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Fri, 16 Dec 2011 14:44:33 +1100 Subject: [python-win32] manifest "Microsoft.Windows.Common-Controls" version="6.0.0.0" => strange problem with pywin32 build 216 ? In-Reply-To: References: Message-ID: <4EEABEA1.1040705@gmail.com> On 19/11/2011 3:23 AM, Robert wrote: > In C:\Python23 and C:\Python26 installations there are > python(s).exe.manifest files which contain > '"Microsoft.Windows.Common-Controls" version="6.0.0.0"' > (see attached/below) > > With pywin32 build 216 (was not in 212; and 214 I guess) win32ui apps, > which are started by these python(w).exe's , a strange auto-magical > button pressing is going on, immediately after application start. almost > any button is pressed when the mouse moves.. By chance its possible to > stop the show in the Task Manager. > > It seems (seen by a debug output), that notification messages (BN_.. > (Which could be routed via HookNotify?)) or so do trigger the normal > HookCommand'ed handler. > When that Common-Controls section (or the whole .manifest) is removed, > the apps work normal in build 216. > > What could be the reason? I've no idea - that sounds really strange. > What does this Common-Control section actually do? I believe it says a new version of the commctrl library which does "xp themes" should be used by the app. Cheers, Mark From skippy.hammond at gmail.com Fri Dec 16 04:59:40 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Fri, 16 Dec 2011 14:59:40 +1100 Subject: [python-win32] python-win32 Digest, Vol 104, Issue 14 In-Reply-To: References: Message-ID: <4EEAC22C.2030106@gmail.com> On 22/11/2011 2:10 PM, ??? wrote: > http://sourceforge.net/tracker/?func=detail&aid=2831327&group_id=78018&atid=551954 > > > UTC / Local time break pythonwin for Python32. > > A lot of function does not work. Simple throws following messages: > > ValueError: astimezone() cannot be applied to a naive datetime I'll try and look at this issue soon. Cheers, Mark From skippy.hammond at gmail.com Fri Dec 16 05:00:49 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Fri, 16 Dec 2011 15:00:49 +1100 Subject: [python-win32] addin fails to load the first time after login In-Reply-To: References: Message-ID: <4EEAC271.4050806@gmail.com> I'm afraid I can't guess without a traceback. Try registering your addin with --debug and then run "python -m win32traceutil" - if you are luck you will also see the traceback there. Mark On 24/11/2011 8:09 AM, Christian K. wrote: > Hi, > > I am observing a strange behaviour of two python com-servers/addins, one > of them is called from Excel VBA the other one is an Outlook (both from > Office 2003) addin. > > Both of them work if I register them and start using Outlook or Excel > thereafter. However when I log out and login the next time, both of them > fail to load. Excel is showing an error message when > CreateObject("addin") is called, showing a python traceback from > somewhere within win32com (only parts of it since the window cannot be > resized). Outlook silently ignores the addin and in the list of > com_addins it is marked as deactivated. Re-registering solves the > problem until the next login. > > Interestingly I get them to work if I start e.g. spyder (a python IDE) > before making calls to the com servers. It does not seem to help though, > if I only open a python shell. This sounds like a timeout issue to me. > > Do you know what might be the cause and what I can do about it? > > Best regards, Christian > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 From skippy.hammond at gmail.com Fri Dec 16 04:58:52 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Fri, 16 Dec 2011 14:58:52 +1100 Subject: [python-win32] Setting a 64bit FILETIME PT_SYSTIME property using pywin32's SetProps() In-Reply-To: References: Message-ID: <4EEAC1FC.1080203@gmail.com> Attempting to pass an integer will assume the int is a regular "unix timestamp" and pywin32 will do the conversions as necessary. So there should be no need to convert it to a 64bit FILETIME integer. You should also find that passing a datetime object directly works, even in py2k builds - pywin32 will use the timetuple() method to perform the conversion. Mark On 21/11/2011 6:03 PM, Sriram ET. wrote: > I am using pywin32 mapi routines to interact with my outlook contacts > store. I am trying to set the PT_BIRTHDAY property and have the > following code for doing that: > > The conversion from and to FILETIME values is from filetimes.py > available at:http://reliablybroken.com/b/wp-content/filetimes.py > > | dt = datetime.strptime('1980-01-01','%Y-%m-%d') > filetime = filetimes.dt_to_filetime(dt) > msg.SetProps([(mapitags.PR_BIRTHDAY, filetime)]) > | > > I get an OverflowError: Python int too large to convert to c long > > I am on a 32 bit machine, and I understand FILETME is a 64 bit value. I > am at a loss. How can I set the underlying MAPI property using this > library? Is there a workaround? > > (Setup: Outlook 2010, Window 7 running on a 32bit virtual machine via > VMWare Fusion 4 on Mac OS X Lion) > > Thanks! > > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 From nawijn at gmail.com Fri Dec 16 16:25:32 2011 From: nawijn at gmail.com (Marco Nawijn) Date: Fri, 16 Dec 2011 16:25:32 +0100 Subject: [python-win32] Problem with Dispatch in normal Python shell Message-ID: Dear All, I hope someone can assist me with a dispatch problem that I am facing. Let me briefly explain my case. I am implementing a monitoring and reporting application for one of our manufacturing machines. I use the COM interface provided by the PLC manufacturer (Siemens). Since it is a long running program and the PythonWin GUI becomes sort of unresponsive I would like to run the data extraction operation through a normal Python shell (DOS/PowerShell terminal). The problem that I face is that I cannot dispatch the automation object through the normal Python shell (see traceback below). It works fine in the interactive PythonWin console (see at the bottom of the post). I would be very gratefull if someone can provide me with some hints on how to solve this problem. Maybe somebody knows the difference in running an interactive console or a normal Python shell? I have been struggling with the issue for a few days now. It is becoming quite urgent now, because we are required to log the manufacturing data on a higher rate than we do now. We have a tool implemented in VB, but is is completely hardcoded to only run at a one minute time interval. We would like to be more flexible, but use Python to do so. Thanks in advance, Marco Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> from win32com.client import Dispatch >>> server = Dispatch('OPC.Automation.1') Traceback (most recent call last): File "", line 1, in File "c:\python27\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,c lsctx) File "c:\python27\lib\site-packages\win32com\client\dynamic.py", line 108, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "c:\python27\lib\site-packages\win32com\client\dynamic.py", line 85, in _ GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.II D_IDispatch) pywintypes.com_error: (-2147023898, 'Invalid access to memory location.', None, None) PythonWin 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32. Portions Copyright 1994-2008 Mark Hammond - see 'Help/About PythonWin' for further copyright information. >>> from win32com.client import Dispatch >>> server = Dispatch('OPC.Automation.1') >>> print server >>> From pacopyc at gmail.com Fri Dec 16 22:42:17 2011 From: pacopyc at gmail.com (pacopyc pacopyc) Date: Fri, 16 Dec 2011 22:42:17 +0100 Subject: [python-win32] send message remote host Message-ID: Hi, I'd like send a message to remote host. I want that remote host's user read my short message immediately. I have remote host administrator credentials. Can you help me? From timr at probo.com Sat Dec 17 02:47:06 2011 From: timr at probo.com (Tim Roberts) Date: Fri, 16 Dec 2011 17:47:06 -0800 Subject: [python-win32] send message remote host In-Reply-To: References: Message-ID: <4EEBF49A.8000103@probo.com> pacopyc pacopyc wrote: > Hi, I'd like send a message to remote host. I want that remote host's > user read my short message immediately. I have remote host > administrator credentials. Can you help me? You'll have to be more specific with what you mean by "message". Are you talking about the same operation that the "net send" command performs? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From sleerssen at gmail.com Sat Dec 17 16:34:17 2011 From: sleerssen at gmail.com (Scott Leerssen) Date: Sat, 17 Dec 2011 10:34:17 -0500 Subject: [python-win32] file descriptor issues using msvcrt.open_osfhandle()+os.fdopen() Message-ID: <32FE529F-0D6B-4D8A-91C3-10809322966B@gmail.com> Greetings! Apologies in advance for the length of this post; after many days of scouring Python and Windows news groups, I've seen reports of issues similar to mine, but no cause or resolution other than re-trying an operation. I'm in no way a Windows programmer; I've spent my entire career on Unix/Linux, so the Windows ways are a bit of a mystery to me at times. That being said, I'm hoping that someone might shed some light on something stupid I've done (limited to this topic, please) or that I might actually save someone else's time when they see this post. I have been tracking down random descriptor issues with a multithreaded Windows service written in Python. The issue presents itself as "bad file descriptor", "attempt to read from something that is not a socket", and various errors closing files and sockets. In my service, I needed to be able to open a file with FILE_FLAG_BACKUP_SEMANTICS, create a Python file object and pass it off to another method to read. Since the Python posix file open() method doesn't provide a way to pass special Windozy flags, and I didn't see a way of setting that post-open, I followed a pattern that I found that looks like this: h = win32file.CreateFile( fname, win32file.GENERIC_READ, win32file.FILE_SHARE_READ, None, win32file.OPEN_EXISTING, win32file.FILE_FLAG_BACKUP_SEMANTICS, None ) fd = msvcrt.open_osfhandle(h, os.O_RDONLY) f = os.fdopen(fd, 'rb') That worked well and I was able to pass that 'f' off to be handled like any other file-like object. However, my multi-threaded service would randomly raise file descriptor errors reading files, logging and writing data on the network. What I found is that the file descriptors in the PyHANDLE and the file object seem to be somewhat out of sync during garbage collection. Closing the PyHANDLE leaves the file object with an invalid descriptor, and closing the file object leaves the PyHANDLE with an invalid descriptor, but only sometimes. If you put the code above into a loop, most of the time it will raise with a bad file descriptor error as the old objects go out of scope and are collected. I tried to remedy that by first calling CloseHandle() on the PyHANDLE and then close() on the file object (wrapped in a a try:..except IOError to deal with the already closed descriptor), and that makes the loop run, but still causes problems with other threads that just happen to open/close a descriptor at the right/wrong time. So, my completely inexperienced (in Windows) empirical diagnosis is that there is some sort of synchronization issue between the msvcrt library and the CPython runtime that results in descriptors being shared among file and socket objects in a multithreaded application. At any rate, I replaced the CreateFile()/msvcrt.open_osfhandle()/os.fdopen() with a wrapper class that uses CreateFile()/ReadFile() and provides a minimal set of file-like object methods and all of my file descriptor and socket problems went away, so either I'm correct, or I just moved my problem. As I said in the beginning of this epic, I'm no more sure that I've found a problem with the underlying classes that manage descriptors on Windows than I've just replaced my own bad code with other not-as-bad code, but I hope that this rings a bell for someone that can set me straight. Thanks, Scott Leerssen From amauryfa at gmail.com Sat Dec 17 17:36:06 2011 From: amauryfa at gmail.com (Amaury Forgeot d'Arc) Date: Sat, 17 Dec 2011 17:36:06 +0100 Subject: [python-win32] file descriptor issues using msvcrt.open_osfhandle()+os.fdopen() In-Reply-To: <32FE529F-0D6B-4D8A-91C3-10809322966B@gmail.com> References: <32FE529F-0D6B-4D8A-91C3-10809322966B@gmail.com> Message-ID: 2011/12/17 Scott Leerssen > Closing the PyHANDLE leaves the file object with an invalid descriptor, > and closing the file object leaves the PyHANDLE with an invalid descriptor, > but only sometimes After open_osfhandle(), the handle is owned by the file object, and should not be closed when the PyHANDLE object is deallocated. Did you try to use the Detach() method? Something like fd = open_osfhandle(h.Detach(), os.O_RDONLY) Documentation says: "You would call this function when you need the underlying win32 handle to exist beyond the lifetime of the handle object" which seems adequate here. -- Amaury Forgeot d'Arc -------------- next part -------------- An HTML attachment was scrubbed... URL: From sleerssen at gmail.com Sat Dec 17 18:08:53 2011 From: sleerssen at gmail.com (Scott Leerssen) Date: Sat, 17 Dec 2011 12:08:53 -0500 Subject: [python-win32] file descriptor issues using msvcrt.open_osfhandle()+os.fdopen() In-Reply-To: References: <32FE529F-0D6B-4D8A-91C3-10809322966B@gmail.com> Message-ID: <84739C66-AF7C-4D0E-AA4D-E4F1AEFDDD1D@gmail.com> On Dec 17, 2011, at 11:36 AM, Amaury Forgeot d'Arc wrote: > 2011/12/17 Scott Leerssen > Closing the PyHANDLE leaves the file object with an invalid descriptor, and closing the file object leaves the PyHANDLE with an invalid descriptor, but only sometimes > > After open_osfhandle(), the handle is owned by the file object, and should not be closed when the PyHANDLE object is deallocated. > Did you try to use the Detach() method? Something like > fd = open_osfhandle(h.Detach(), os.O_RDONLY) > Documentation says: "You would call this function when you need the underlying win32 handle to exist beyond the lifetime of the handle object" which seems adequate here. I did see that, but I interpreted that to mean that the PyHANDLE would be dereferenced from the underlying Windows file handle, and I'm not sure what the consequences of that would be. That is, how would I free that resource if I lose it from the Python context? Also, it didn't seem to fit since I didn't want a win32 handle to live past the close. I just wanted all the associated handles and descriptors to close at the same time. -------------- next part -------------- An HTML attachment was scrubbed... URL: From amauryfa at gmail.com Sat Dec 17 18:25:57 2011 From: amauryfa at gmail.com (Amaury Forgeot d'Arc) Date: Sat, 17 Dec 2011 18:25:57 +0100 Subject: [python-win32] file descriptor issues using msvcrt.open_osfhandle()+os.fdopen() In-Reply-To: <84739C66-AF7C-4D0E-AA4D-E4F1AEFDDD1D@gmail.com> References: <32FE529F-0D6B-4D8A-91C3-10809322966B@gmail.com> <84739C66-AF7C-4D0E-AA4D-E4F1AEFDDD1D@gmail.com> Message-ID: 2011/12/17 Scott Leerssen > I did see that, but I interpreted that to mean that the PyHANDLE would be > dereferenced from the underlying Windows file handle, > It's the other way round: the PyHandle just forgets the win32 handle value, and will not close it in its __del__. -- Amaury Forgeot d'Arc -------------- next part -------------- An HTML attachment was scrubbed... URL: From sleerssen at gmail.com Sat Dec 17 18:34:37 2011 From: sleerssen at gmail.com (Scott Leerssen) Date: Sat, 17 Dec 2011 12:34:37 -0500 Subject: [python-win32] file descriptor issues using msvcrt.open_osfhandle()+os.fdopen() In-Reply-To: References: <32FE529F-0D6B-4D8A-91C3-10809322966B@gmail.com> <84739C66-AF7C-4D0E-AA4D-E4F1AEFDDD1D@gmail.com> Message-ID: <0DD1C7B3-CB99-44FE-AAEA-8E0F998B16C8@gmail.com> On Dec 17, 2011, at 12:25 PM, Amaury Forgeot d'Arc wrote: > 2011/12/17 Scott Leerssen > I did see that, but I interpreted that to mean that the PyHANDLE would be dereferenced from the underlying Windows file handle, > > It's the other way round: the PyHandle just forgets the win32 handle value, and will not close it in its __del__. Sorry, I did write that backward. How is the win32 handle freed? -------------- next part -------------- An HTML attachment was scrubbed... URL: From pacopyc at gmail.com Sat Dec 17 22:48:01 2011 From: pacopyc at gmail.com (pacopyc pacopyc) Date: Sat, 17 Dec 2011 22:48:01 +0100 Subject: [python-win32] send message remote host Message-ID: Yes, I'm thinking about "net send" of Windows From christophedeze at wanadoo.fr Mon Dec 19 12:57:49 2011 From: christophedeze at wanadoo.fr (cd) Date: Mon, 19 Dec 2011 12:57:49 +0100 (CET) Subject: [python-win32] rename computer Message-ID: <24572038.67645.1324295869582.JavaMail.www@wwinf2210> hello I didn't find any example of howto rename a windows computer with python ? i've tried with wmi unsuccessfully .... thanks for any halps Christophe From mail at timgolden.me.uk Mon Dec 19 14:47:16 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 19 Dec 2011 13:47:16 +0000 Subject: [python-win32] rename computer In-Reply-To: <24572038.67645.1324295869582.JavaMail.www@wwinf2210> References: <24572038.67645.1324295869582.JavaMail.www@wwinf2210> Message-ID: <4EEF4064.6030700@timgolden.me.uk> On 19/12/2011 11:57, cd wrote: > hello > I didn't find any example of howto rename a windows computer with python ? > > i've tried with wmi unsuccessfully .... What did you try with WMI, and what happened? TJG From christophedeze at wanadoo.fr Mon Dec 19 15:26:17 2011 From: christophedeze at wanadoo.fr (cd) Date: Mon, 19 Dec 2011 15:26:17 +0100 (CET) Subject: [python-win32] rename computer In-Reply-To: References: <24572038.67645.1324295869582.JavaMail.www@wwinf2210> Message-ID: <1085245363.199514.1324304777960.JavaMail.www@wwinf1g27> thanks it works but I prefere to use a builtin" system call or somethings like this, in order to avoid invalid hostname. I hope wmi can valid hostname for me > Message du 19/12/11 14:31 > De : "Scott Leerssen" > A : "cd" > Copie ? : > Objet : Re: [python-win32] rename computer > > > On Dec 19, 2011, at 6:57 AM, cd wrote: > > > hello > > I didn't find any example of howto rename a windows computer with python ? > > > > i've tried with wmi unsuccessfully .... > > > > thanks for any halps > > > > Christophe > > I do it by setting the following registry values: > > 'HKLM\\System\\CurrentControlSet\\Control\\ComputerName\\ComputerName', > 'ComputerName', > > 'HKLM\\System\\CurrentControlSet\\Control\\ComputerName\\ActiveComputerName', > 'ComputerName', > > DHCP might set the following for you, but if you are using static addressing, you'll want to set them as well: > > 'HKLM'\\System\\CurrentControlSet\\Services\\Tcpip\\Parameters', > 'Hostname', > > 'HKLM\\System\\CurrentControlSet\\Services\\Tcpip\\Parameters', > 'NV Hostname', > > > From christophedeze at wanadoo.fr Mon Dec 19 15:20:38 2011 From: christophedeze at wanadoo.fr (cd) Date: Mon, 19 Dec 2011 15:20:38 +0100 (CET) Subject: [python-win32] rename computer In-Reply-To: <4EEF4064.6030700@timgolden.me.uk> References: <24572038.67645.1324295869582.JavaMail.www@wwinf2210> <4EEF4064.6030700@timgolden.me.uk> Message-ID: <210200286.198995.1324304438070.JavaMail.www@wwinf1g27> import wmi c = wmi.WMI().Win32_ComputerSystem computer = c()[0] for propertyName in sorted( list( c.properties ) ): if propertyName == 'Name': print setattr( computer, propertyName, 'newname' ) ... Traceback (most recent call last): File "", line 3, in File "C:\Python27\lib\site-packages\wmi.py", line 571, in __setattr__ handle_com_error () File "C:\Python27\lib\site-packages\wmi.py", line 241, in handle_com_error raise klass (com_error=err) wmi.x_wmi: > Message du 19/12/11 14:48 > De : "Tim Golden" > A : python-win32 at python.org > Copie ? : > Objet : Re: [python-win32] rename computer > > On 19/12/2011 11:57, cd wrote: > > hello > > I didn't find any example of howto rename a windows computer with python ? > > > > i've tried with wmi unsuccessfully .... > > What did you try with WMI, and what happened? > > TJG > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > From mail at timgolden.me.uk Mon Dec 19 15:32:36 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 19 Dec 2011 14:32:36 +0000 Subject: [python-win32] rename computer In-Reply-To: <210200286.198995.1324304438070.JavaMail.www@wwinf1g27> References: <24572038.67645.1324295869582.JavaMail.www@wwinf2210> <4EEF4064.6030700@timgolden.me.uk> <210200286.198995.1324304438070.JavaMail.www@wwinf1g27> Message-ID: <4EEF4B04.8050300@timgolden.me.uk> On 19/12/2011 14:20, cd wrote: > import wmi > c = wmi.WMI().Win32_ComputerSystem > computer = c()[0] > for propertyName in sorted( list( c.properties ) ): > if propertyName == 'Name': > print setattr( computer, propertyName, 'newname' ) Ah. I'm afraid, good as WMI is, it's not that good. You need to invoke the right method on the Win32_ComputerSystem instance. The appropriate method is referenced here: http://msdn.microsoft.com/en-us/library/windows/desktop/aa393056%28v=vs.85%29.aspx There are some examples here: http://msdn.microsoft.com/en-us/library/windows/desktop/aa394586%28v=vs.85%29.aspx and the (definitely untested) Python equivalent is something like this: import wmi c = wmi.WMI () for system in c.Win32_ComputerSystem (): system.Rename ("NEW-NAME", "TIM", "PASSWORD") TJG From christophedeze at wanadoo.fr Mon Dec 19 15:55:01 2011 From: christophedeze at wanadoo.fr (cd) Date: Mon, 19 Dec 2011 15:55:01 +0100 (CET) Subject: [python-win32] rename computer In-Reply-To: <4EEF4B04.8050300@timgolden.me.uk> References: <24572038.67645.1324295869582.JavaMail.www@wwinf2210> <4EEF4064.6030700@timgolden.me.uk> <210200286.198995.1324304438070.JavaMail.www@wwinf1g27> <4EEF4B04.8050300@timgolden.me.uk> Message-ID: <1845251643.201646.1324306501654.JavaMail.www@wwinf1g27> thanks genius it works !! > Message du 19/12/11 15:34 > De : "Tim Golden" > A : python-win32 at python.org > Copie ? : > Objet : Re: [python-win32] rename computer > > On 19/12/2011 14:20, cd wrote: > > import wmi > > c = wmi.WMI().Win32_ComputerSystem > > computer = c()[0] > > for propertyName in sorted( list( c.properties ) ): > > if propertyName == 'Name': > > print setattr( computer, propertyName, 'newname' ) > > Ah. > > I'm afraid, good as WMI is, it's not that good. You need to > invoke the right method on the Win32_ComputerSystem instance. > > The appropriate method is referenced here: > > http://msdn.microsoft.com/en-us/library/windows/desktop/aa393056%28v=vs.85%29.aspx > > > There are some examples here: > > http://msdn.microsoft.com/en-us/library/windows/desktop/aa394586%28v=vs.85%29.aspx > > > and the (definitely untested) Python equivalent is something > like this: > > > import wmi > > c = wmi.WMI () > for system in c.Win32_ComputerSystem (): > system.Rename ("NEW-NAME", "TIM", "PASSWORD") > > > > TJG > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > From mail at timgolden.me.uk Mon Dec 19 16:06:37 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 19 Dec 2011 15:06:37 +0000 Subject: [python-win32] rename computer In-Reply-To: <4EEF4B04.8050300@timgolden.me.uk> References: <24572038.67645.1324295869582.JavaMail.www@wwinf2210> <4EEF4064.6030700@timgolden.me.uk> <210200286.198995.1324304438070.JavaMail.www@wwinf1g27> <4EEF4B04.8050300@timgolden.me.uk> Message-ID: <4EEF52FD.4010901@timgolden.me.uk> On 19/12/2011 14:32, Tim Golden wrote: > > import wmi > > c = wmi.WMI () > for system in c.Win32_ComputerSystem (): > system.Rename ("NEW-NAME", "TIM", "PASSWORD") > > For the record, the OP reported in private email that this solution works for him. TJG From theller at ctypes.org Mon Dec 19 16:26:08 2011 From: theller at ctypes.org (Thomas Heller) Date: Mon, 19 Dec 2011 16:26:08 +0100 Subject: [python-win32] Several, totally isolated Python interpreters in the same process Message-ID: I made an experiment that I wanted to share because it is imo kind of cool: I managed to embed a second Python interpreter in a Python process, with help of WinSxS (WinSxS is a Microsoft technology that allows to isolate plugins from other plugins, or from the calling process). The second interpreter is totally isolated from the calling process. The idea is to use this technology to decouple COM extensions implemented in Python from the caller and from other COM extensions. But there may be other uses as well... The code is here: http://code.google.com/p/ctypes-stuff/source/browse/trunk/winsxs Information I found useful about WinSxS and assemblies: http://msdn.microsoft.com/en-us/library/dd408052%28v=VS.85%29.aspx http://omnicognate.wordpress.com/2009/10/05/winsxs/ Thomas From sdementen at gmail.com Mon Dec 19 17:17:07 2011 From: sdementen at gmail.com (=?ISO-8859-1?Q?S=E9bastien_de_Menten?=) Date: Mon, 19 Dec 2011 17:17:07 +0100 Subject: [python-win32] wrapping a IUnknown pointer into a Dispatch interface Message-ID: Hello, I am using a call to a windows function via ctypes to retrieve a pointer to the IDispatch interface of an Excel application, something like: oledll.oleacc.AccessibleObjectFromWindow(hnd, OBJID_NATIVEOM, byref(automation.IDispatch._iid_), byref(pointer_idispatch)) where hnd is the window handle to the proper excel window. In the variable result (with type POINTER(IUnknown)), I have the pointer to the interface. Currently, to be able to call methods/properties on this COM object, I call the "wrap" function from the comtypes.client library and then use the COM object, something like: app = wrap( pointer_idispatch ) print app.Application.Name '==> "Microsoft Excel" app.Application.ActiveWorkbook.ActiveSheet.Cells(1,1).Value[()] = 1 However, this is slow (a coupe of seconds to do the wrap) and the resulting object is less friendly to use than the COM object I can get with win32. For instance, i need to use app.Application.ActiveWorkbook.ActiveSheet.Cells(1,1).Value[()] = 1 instead of app.Application.ActiveWorkbook.ActiveSheet.Cells(1,1).Value = 1 So my question, how could I instantiate a COM IDispatch object from win32 (equivalent of 'app' hereabove) when I have the pointer to the IDispatch interface ('pointer_idispatch' hereabove) ? thank you Sebastien -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Mon Dec 19 19:19:32 2011 From: timr at probo.com (Tim Roberts) Date: Mon, 19 Dec 2011 10:19:32 -0800 Subject: [python-win32] send message remote host In-Reply-To: References: Message-ID: <4EEF8034.6050808@probo.com> pacopyc pacopyc wrote: > Yes, I'm thinking about "net send" of Windows As Google would have told you, "net send" uses the API NetMessageBufferSend, which is in the win32net module in PyWin32. There are samples on the Internet, although you might have to translate the C++ to Python. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From skippy.hammond at gmail.com Mon Dec 19 22:29:41 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Tue, 20 Dec 2011 08:29:41 +1100 Subject: [python-win32] Problem with Dispatch in normal Python shell In-Reply-To: References: Message-ID: <4EEFACC5.7010305@gmail.com> I'm afraid it looks like the object itself has a problem when running outside a GUI environment. You might like to see if you can use Windows Scripting Host (cscript.exe) to load the object but I suspect that might fail in the same way. If so, your best bet might be to talk to the vendor. Mark On 17/12/2011 2:25 AM, Marco Nawijn wrote: > Dear All, > > I hope someone can assist me with a dispatch problem that I am facing. > Let me briefly explain my case. I am implementing a monitoring and > reporting application for one of our manufacturing machines. I use the > COM interface provided by the PLC manufacturer (Siemens). Since it is > a long running program and the PythonWin GUI becomes sort of > unresponsive I would like to run the data extraction operation through > a normal Python shell (DOS/PowerShell terminal). The problem that I > face is that I cannot dispatch the automation object through the > normal Python shell (see traceback below). It works fine in the > interactive PythonWin console (see at the bottom of the post). I would > be very gratefull if someone can provide me with some hints on how to > solve this problem. Maybe somebody knows the difference in running an > interactive console or a normal Python shell? > > I have been struggling with the issue for a few days now. It is > becoming quite urgent now, because we are required to log the > manufacturing data on a higher rate than we do now. We have a tool > implemented in VB, but is is completely hardcoded to only run at a one > minute time interval. We would like to be more flexible, but use > Python to do so. > > Thanks in advance, > > Marco > > > > Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win > 32 > Type "help", "copyright", "credits" or "license" for more information. >>>> from win32com.client import Dispatch >>>> server = Dispatch('OPC.Automation.1') > Traceback (most recent call last): > File "", line 1, in > File "c:\python27\lib\site-packages\win32com\client\__init__.py", line 95, in > Dispatch > dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,c > lsctx) > File "c:\python27\lib\site-packages\win32com\client\dynamic.py", line 108, in > _GetGoodDispatchAndUserName > return (_GetGoodDispatch(IDispatch, clsctx), userName) > File "c:\python27\lib\site-packages\win32com\client\dynamic.py", line 85, in _ > GetGoodDispatch > IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.II > D_IDispatch) > pywintypes.com_error: (-2147023898, 'Invalid access to memory location.', None, > None) > > > > PythonWin 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit > (Intel)] on win32. > Portions Copyright 1994-2008 Mark Hammond - see 'Help/About PythonWin' > for further copyright > information. > >>>> from win32com.client import Dispatch > >>>> server = Dispatch('OPC.Automation.1') > >>>> print server > > 0x16331400> > >>>> > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 From skippy.hammond at gmail.com Mon Dec 19 22:32:59 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Tue, 20 Dec 2011 08:32:59 +1100 Subject: [python-win32] file descriptor issues using msvcrt.open_osfhandle()+os.fdopen() In-Reply-To: <0DD1C7B3-CB99-44FE-AAEA-8E0F998B16C8@gmail.com> References: <32FE529F-0D6B-4D8A-91C3-10809322966B@gmail.com> <84739C66-AF7C-4D0E-AA4D-E4F1AEFDDD1D@gmail.com> <0DD1C7B3-CB99-44FE-AAEA-8E0F998B16C8@gmail.com> Message-ID: <4EEFAD8B.5050901@gmail.com> On 18/12/2011 4:34 AM, Scott Leerssen wrote: > > On Dec 17, 2011, at 12:25 PM, Amaury Forgeot d'Arc wrote: > >> 2011/12/17 Scott Leerssen > > >> >> I did see that, but I interpreted that to mean that the PyHANDLE >> would be dereferenced from the underlying Windows file handle, >> >> >> It's the other way round: the PyHandle just forgets the win32 handle >> value, and will not close it in its __del__. > > Sorry, I did write that backward. How is the win32 handle freed? The .Detach() method returns an integer handle value which can then be closed using win32api.CloseHandle(). Mark From sleerssen at gmail.com Mon Dec 19 22:34:42 2011 From: sleerssen at gmail.com (Scott Leerssen) Date: Mon, 19 Dec 2011 16:34:42 -0500 Subject: [python-win32] file descriptor issues using msvcrt.open_osfhandle()+os.fdopen() In-Reply-To: <4EEFAD8B.5050901@gmail.com> References: <32FE529F-0D6B-4D8A-91C3-10809322966B@gmail.com> <84739C66-AF7C-4D0E-AA4D-E4F1AEFDDD1D@gmail.com> <0DD1C7B3-CB99-44FE-AAEA-8E0F998B16C8@gmail.com> <4EEFAD8B.5050901@gmail.com> Message-ID: <921F76B1-25C1-4E69-B0FE-F05B48796DEB@gmail.com> On Dec 19, 2011, at 4:32 PM, Mark Hammond wrote: > On 18/12/2011 4:34 AM, Scott Leerssen wrote: >> >> On Dec 17, 2011, at 12:25 PM, Amaury Forgeot d'Arc wrote: >> >>> 2011/12/17 Scott Leerssen >> > >>> >>> I did see that, but I interpreted that to mean that the PyHANDLE >>> would be dereferenced from the underlying Windows file handle, >>> >>> >>> It's the other way round: the PyHandle just forgets the win32 handle >>> value, and will not close it in its __del__. >> >> Sorry, I did write that backward. How is the win32 handle freed? > > The .Detach() method returns an integer handle value which can then be closed using win32api.CloseHandle(). > Excellent! Thanks! From randfb at yahoo.com Mon Dec 19 23:24:00 2011 From: randfb at yahoo.com (Rand Batchelder) Date: Mon, 19 Dec 2011 14:24:00 -0800 (PST) Subject: [python-win32] Problem : COM with Array Argument Message-ID: <1324333440.84831.YahooMailNeo@web160901.mail.bf1.yahoo.com> I ran makepy on the DesignCad 20 type library. I get Type mismatch errors with the function GetPoints: a subset of the class definition is: """ class IDcadEntity(DispatchBaseClass): ??? CLSID = IID('{B4D5DA6E-EDEB-4816-BD4C-88C04C119C24}') ??? coclass_clsid = IID('{4FCCD850-D360-458C-8FB1-61CB90A28137}') ??? def GetPoint(self, iIndex=defaultNamedNotOptArg, dX=pythoncom.Missing, dY=pythoncom.Missing, dZ=pythoncom.Missing): ??? ??? return self._ApplyTypes_(13, 1, (11, 0), ((2, 1), (16389, 2), (16389, 2), (16389, 2)), u'GetPoint', None,iIndex ??? ??? ??? , dX, dY, dZ) ??? def GetPoints(self, iStartIndex=defaultNamedNotOptArg, iCount=defaultNamedNotOptArg, pXYZArray=defaultNamedNotOptArg): ??? ??? return self._ApplyTypes_(15, 1, (2, 0), ((2, 1), (2, 1), (24581, 3)), u'GetPoints', None,iStartIndex ??? ??? ??? , iCount, pXYZArray) """ I tried Ent.GetPoints(1,1, d) where d is a list of 3 floats, I get the following errors: Traceback (most recent call last): ? File "", line 1, in ? File "C:\Python27\lib\site-packages\win32com\gen_py\DD0F69E1-1E0D-4064-94FA-2ED7ADC72C5Dx0x20x0.py", line 4631, in GetPoints ??? , iCount, pXYZArray) ? File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 456, in _ApplyTypes_ ??? self._oleobj_.InvokeTypes(dispid, 0, wFlags, retType, argTypes, *args), com_error: (-2147352571, 'Type mismatch.', None, 3) Please advise thanks Rand Batchelder -------------- next part -------------- An HTML attachment was scrubbed... URL: From sleerssen at gmail.com Mon Dec 19 23:37:09 2011 From: sleerssen at gmail.com (Scott Leerssen) Date: Mon, 19 Dec 2011 17:37:09 -0500 Subject: [python-win32] file descriptor issues using msvcrt.open_osfhandle()+os.fdopen() In-Reply-To: <0FFA640B-7F3C-4B73-B32A-65ED196D6B1F@gmail.com> References: <32FE529F-0D6B-4D8A-91C3-10809322966B@gmail.com> <84739C66-AF7C-4D0E-AA4D-E4F1AEFDDD1D@gmail.com> <0DD1C7B3-CB99-44FE-AAEA-8E0F998B16C8@gmail.com> <4EEFAD8B.5050901@gmail.com> <919906B4-07CF-44E0-B332-2D1804A9737C@gmail.com> <4EEFB429.9050300@skippinet.com.au> <0FFA640B-7F3C-4B73-B32A-65ED196D6B1F@gmail.com> Message-ID: adding python-win32 to the rest of the thread... I missed a reply-all in here somewhere... On Dec 19, 2011, at 5:06 PM, Scott Leerssen wrote: > > On Dec 19, 2011, at 5:01 PM, Mark Hammond wrote: > >> Note you are also closing h. But more generally, I wouldn't be at all surprised to find that closing fd also closes the win32 handle associated with it, otherwise every CRT handle ever opened would leak the OS handle. > > It does close the descriptor. However, I still see screwy behavior with other sockets and descriptors in other threads. It's almost like there are two sides of the descriptor, and one gets reused before the other is released, resulting in unexpected closure of descriptors or "stealing" of one threads descriptor when another thread opens a file or socket. It is truly odd. > >> IOW, I think you can just detach it and ignore closing it. >> >> Mark >> >> On 20/12/2011 8:43 AM, Scott Leerssen wrote: >>> >>> On Dec 19, 2011, at 4:32 PM, Mark Hammond wrote: >>> >>>> On 18/12/2011 4:34 AM, Scott Leerssen wrote: >>>>> >>>>> On Dec 17, 2011, at 12:25 PM, Amaury Forgeot d'Arc wrote: >>>>> >>>>>> 2011/12/17 Scott Leerssen>>>>> > >>>>>> >>>>>> I did see that, but I interpreted that to mean that the PyHANDLE >>>>>> would be dereferenced from the underlying Windows file handle, >>>>>> >>>>>> >>>>>> It's the other way round: the PyHandle just forgets the win32 handle >>>>>> value, and will not close it in its __del__. >>>>> >>>>> Sorry, I did write that backward. How is the win32 handle freed? >>>> >>>> The .Detach() method returns an integer handle value which can then be closed using win32api.CloseHandle(). >>> >>> I just tried that, and after closing the file object and attempting to call win32api.ClosHandle() on the value returned by detach, I get an exception of "error: (6, 'CloseHandle', 'The handle is invalid.')" Here's what the code looks like: >>> >>> h = win32file.CreateFile( >>> fname, >>> win32file.GENERIC_READ, >>> win32file.FILE_SHARE_READ, >>> None, >>> win32file.OPEN_EXISTING, >>> win32file.FILE_FLAG_BACKUP_SEMANTICS, >>> None >>> ) >>> hd = h.Detach() >>> fd = msvcrt.open_osfhandle(hd, os.O_RDONLY) >>> f = os.fdopen(fd, 'rb') >>> f.read() >>> f.close() >>> h.Close() >>> win32file.CloseHandle(hd) >>> >>> >> > From timr at probo.com Mon Dec 19 23:59:22 2011 From: timr at probo.com (Tim Roberts) Date: Mon, 19 Dec 2011 14:59:22 -0800 Subject: [python-win32] Problem : COM with Array Argument In-Reply-To: <1324333440.84831.YahooMailNeo@web160901.mail.bf1.yahoo.com> References: <1324333440.84831.YahooMailNeo@web160901.mail.bf1.yahoo.com> Message-ID: <4EEFC1CA.7080107@probo.com> Rand Batchelder wrote: > I ran makepy on the DesignCad 20 type library. > > I get Type mismatch errors with the function GetPoints: > ... > def GetPoints(self, iStartIndex=defaultNamedNotOptArg, > iCount=defaultNamedNotOptArg, pXYZArray=defaultNamedNotOptArg): > return self._ApplyTypes_(15, 1, (2, 0), ((2, 1), (2, 1), > (24581, 3)), u'GetPoints', None,iStartIndex > , iCount, pXYZArray) > """ > I tried Ent.GetPoints(1,1, d) > where d is a list of 3 floats, > > I get the following errors: > Traceback (most recent call last): > ... > File "C:\Python27\lib\site-packages\win32com\client\__init__.py", > line 456, in _ApplyTypes_ > self._oleobj_.InvokeTypes(dispid, 0, wFlags, retType, argTypes, > *args), > com_error: (-2147352571, 'Type mismatch.', None, 3) There's not an awful lot we can do here. Type code 24581 is a COM safe array of doubles, passed by reference. That seems to be what the documentation shows. You'd sure your values were all floats? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From amauryfa at gmail.com Tue Dec 20 01:38:47 2011 From: amauryfa at gmail.com (Amaury Forgeot d'Arc) Date: Tue, 20 Dec 2011 01:38:47 +0100 Subject: [python-win32] file descriptor issues using msvcrt.open_osfhandle()+os.fdopen() In-Reply-To: References: <32FE529F-0D6B-4D8A-91C3-10809322966B@gmail.com> <84739C66-AF7C-4D0E-AA4D-E4F1AEFDDD1D@gmail.com> <0DD1C7B3-CB99-44FE-AAEA-8E0F998B16C8@gmail.com> <4EEFAD8B.5050901@gmail.com> <919906B4-07CF-44E0-B332-2D1804A9737C@gmail.com> <4EEFB429.9050300@skippinet.com.au> <0FFA640B-7F3C-4B73-B32A-65ED196D6B1F@gmail.com> Message-ID: 2011/12/19 Scott Leerssen > >>> I just tried that, and after closing the file object and attempting to > call win32api.ClosHandle() on the value returned by detach, I get an > exception of "error: (6, 'CloseHandle', 'The handle is invalid.')" Here's > what the code looks like: > >>> > >>> h = win32file.CreateFile( > >>> fname, > >>> win32file.GENERIC_READ, > >>> win32file.FILE_SHARE_READ, > >>> None, > >>> win32file.OPEN_EXISTING, > >>> win32file.FILE_FLAG_BACKUP_SEMANTICS, > >>> None > >>> ) > >>> hd = h.Detach() > >>> fd = msvcrt.open_osfhandle(hd, os.O_RDONLY) > >>> f = os.fdopen(fd, 'rb') > >>> f.read() > >>> f.close() > >>> h.Close() > >>> win32file.CloseHandle(hd) > - h was Detach()ed, so h.Close() is a no-op. - you should not win32file.CloseHandle(hd), the handle now owned by the file object: f.close() called the C function fclose(), which called close(fd) which called CloseHandle. f.close() is enough here! -- Amaury Forgeot d'Arc -------------- next part -------------- An HTML attachment was scrubbed... URL: From sleerssen at gmail.com Tue Dec 20 04:38:58 2011 From: sleerssen at gmail.com (Scott Leerssen) Date: Mon, 19 Dec 2011 22:38:58 -0500 Subject: [python-win32] file descriptor issues using msvcrt.open_osfhandle()+os.fdopen() In-Reply-To: References: <32FE529F-0D6B-4D8A-91C3-10809322966B@gmail.com> <84739C66-AF7C-4D0E-AA4D-E4F1AEFDDD1D@gmail.com> <0DD1C7B3-CB99-44FE-AAEA-8E0F998B16C8@gmail.com> <4EEFAD8B.5050901@gmail.com> <919906B4-07CF-44E0-B332-2D1804A9737C@gmail.com> <4EEFB429.9050300@skippinet.com.au> <0FFA640B-7F3C-4B73-B32A-65ED196D6B1F@gmail.com> Message-ID: On Dec 19, 2011, at 7:38 PM, Amaury Forgeot d'Arc wrote: > 2011/12/19 Scott Leerssen > >>> I just tried that, and after closing the file object and attempting to call win32api.ClosHandle() on the value returned by detach, I get an exception of "error: (6, 'CloseHandle', 'The handle is invalid.')" Here's what the code looks like: > >>> > >>> h = win32file.CreateFile( > >>> fname, > >>> win32file.GENERIC_READ, > >>> win32file.FILE_SHARE_READ, > >>> None, > >>> win32file.OPEN_EXISTING, > >>> win32file.FILE_FLAG_BACKUP_SEMANTICS, > >>> None > >>> ) > >>> hd = h.Detach() > >>> fd = msvcrt.open_osfhandle(hd, os.O_RDONLY) > >>> f = os.fdopen(fd, 'rb') > >>> f.read() > >>> f.close() > >>> h.Close() > >>> win32file.CloseHandle(hd) > > - h was Detach()ed, so h.Close() is a no-op. > - you should not win32file.CloseHandle(hd), the handle now owned by the file object: > f.close() called the C function fclose(), which called close(fd) which called CloseHandle. > > f.close() is enough here! Thanks, that's very helpful. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Tue Dec 20 14:20:55 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 20 Dec 2011 13:20:55 +0000 Subject: [python-win32] Several, totally isolated Python interpreters in the same process In-Reply-To: References: Message-ID: <4EF08BB7.1070102@timgolden.me.uk> On 19/12/2011 15:26, Thomas Heller wrote: > I made an experiment that I wanted to share because it is imo kind of cool: > > I managed to embed a second Python interpreter in a Python process, with > help of WinSxS (WinSxS is a Microsoft technology that allows to isolate > plugins from other plugins, or from the calling process). > > The second interpreter is totally isolated from the calling process. > > The idea is to use this technology to decouple COM extensions > implemented in Python from the caller and from other COM extensions. Looks really interesting. I haven't a clue how I might use it, but I'd love to find a reason to ... TJG From randfb at yahoo.com Wed Dec 21 15:18:28 2011 From: randfb at yahoo.com (randfb) Date: Wed, 21 Dec 2011 06:18:28 -0800 (PST) Subject: [python-win32] Problem : COM with Array Argument In-Reply-To: <4EEFC1CA.7080107@probo.com> References: <1324333440.84831.YahooMailNeo@web160901.mail.bf1.yahoo.com> <4EEFC1CA.7080107@probo.com> Message-ID: <1324477108139-2080239.post@n6.nabble.com> >There's not an awful lot we can do here. Type code 24581 is a COM safe >array of doubles, passed by reference. That seems to be what the >documentation shows. You'd sure your values were all floats? >> I tried Ent.GetPoints(1,1, d) >> where d is a list of 3 floats, Yes I tried various arrangements like: d=[0.0, 0.0, 0.0] Has anyone ever been able to read or write a SAFEARRY from python thru COM ? -- View this message in context: http://python.6.n6.nabble.com/Problem-COM-with-Array-Argument-tp1964132p2080239.html Sent from the Python - python-win32 mailing list archive at Nabble.com. From kxroberto at googlemail.com Tue Dec 27 17:58:16 2011 From: kxroberto at googlemail.com (Robert) Date: Tue, 27 Dec 2011 17:58:16 +0100 Subject: [python-win32] SIGSEGV crash at the end of apps using win32uiole / OCX Message-ID: This is about a ugly old bug which I dislike for long, which I can only suppress by a os._exit() near Python end. Now I found some more info. Perhaps somebody sees what it is about? When a GUI app has ever used a win32uiole OCX like shown in the attached minimal example (pythonwin\pywin\Demos\ocx\webbrowser.py, just changed to use a standalone frame window), then at the very end of the app after all windows have been destroyed and Pythons sort of main() with destruction of all Python objects is reached, there is a SIGSEGV like shown below in python26!PyInterpreterState_Clear (). Reproduced with various Python 2 versions. Notes: * Obviously extra threads are created by the browser OCX if at least one .Navigate() occurred. * if .Navigate() is commented out, and just the Window/OCX creations/destructions are done the problem is not. (But then gdb doesn't show creation of extra threads. Thus the problem seems to have to do with extra threads.) * "app.Run()" is commented out for a mere standalone run, to reproduce the bug easily. Thus the windows are drawn down right after creation. If not, then at exit, this (simple) app somehow doesn't terminate but seems to wait eternally because of extra IE4 threads (?). When run with gdb as shown, the hang/eternal wait yet is not and the SIGSEGV occurs after .Run() too (!?) * the problem is not, when the example is run in Pythonwin.exe at the end of Pythonwin.exe. The problem is not when such script is run with py2exe v0.5.2 stub. (maybe that does rather quickly something like os._exit() at the end). But the problem occurs with current py2exe 0.6.9 stub, and with all normal python(w).exe's - direct start or via interactive sessions. When Pythonwin is run via python(w).exe and "import pywin.framework.startup .... app.Run()", and when then the webbcrash.py is executed, then after exit of Pythonwin the crash is there too. Thus Pythonwin.exe unlike python(w).exe seems to do just a sloppy cleanup (like py2exe0.5.2) and thus avoid the problem. * when os._exit() is done at the end of the script, the problem is not existing: the ugly "solution" ;-) sys.exit() doesn't "solve" - probably because it doesn't prevent against destruction of all Python objects, threads ... * pywin32 build 216 (but same with 214) * BTW: if the original pythonwin\pywin\Demos\ocx\webbrowser.py (using a MDIClient) is run standalone through python(w).exe, there is also a ugly SIGSEGV or even worse C-level crash - now at start. It should only raise a Python exception due to the non-working MDI setup I guess. Robert =========== SIGSEV of webbcrash.py watched with gdb : SIGSEGV: code "mov 0x4(%ebx),%eax" at 0x1e02e449 points to memory 0x00000004. cannot read. C:\scratch>python26 webbcrash.py Run() ... Run() terminated. ==> SIGSEGV crash [uncomment "##app.Run()"] C:\scratch>gdb python26 webbcrash.py GNU gdb (GDB) 7.2 Copyright (C) 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "mingw32". For bug reporting instructions, please see: ... Reading symbols from C:\bin/python26.exe...(no debugging symbols found)...done. "C:\scratch/webbcrash.py" is not a core dump: File format not recognized (gdb) run Starting program: C:\bin/python26.exe (NOTE: ITS THE SAME WITH C:\Python26\python.exe) [New Thread 6740.0x10bc] Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on2 win32 Type "help", "copyright", "credits" or "license" for more information. >>> execfile('webbcrash.py') Web Browser - http://www.google.com/ [New Thread 6740.0x19d0] [New Thread 6740.0xdec] [New Thread 6740.0x1d90] [New Thread 6740.0x1f00] [New Thread 6740.0x19cc] [New Thread 6740.0x26c] [New Thread 6740.0x118c] [New Thread 6740.0x153c] [New Thread 6740.0x1da0] >>> exit() Program received signal SIGSEGV, Segmentation fault. 0x1e02e449 in python26!PyInterpreterState_Clear () from C:\WINDOWS\system32\python26.dll (gdb) bt #0 0x1e02e449 in python26!PyInterpreterState_Clear () from C:\WINDOWS\system32\python26.dll #1 0x00000000 in ?? () (gdb) disass ... 0x1e02e408 <+246>: call 0x1e02e464 0x1e02e40d <+251>: mov %eax,0x50(%esi) 0x1e02e410 <+254>: mov %edi,0x40(%esi) 0x1e02e413 <+257>: mov %edi,0x28(%esi) 0x1e02e416 <+260>: mov %edi,0x2c(%esi) 0x1e02e419 <+263>: mov %edi,0x30(%esi) 0x1e02e41c <+266>: mov %edi,0x34(%esi) 0x1e02e41f <+269>: mov %edi,0x38(%esi) 0x1e02e422 <+272>: mov %edi,0x3c(%esi) 0x1e02e425 <+275>: mov %edi,0x18(%esi) 0x1e02e428 <+278>: mov %edi,0x1c(%esi) 0x1e02e42b <+281>: mov %edi,0x20(%esi) 0x1e02e42e <+284>: mov %edi,0x24(%esi) 0x1e02e431 <+287>: cmp %edi,0xc(%esp) 0x1e02e435 <+291>: je 0x1e02e43c 0x1e02e437 <+293>: call 0x1e03111b 0x1e02e43c <+298>: push $0x1 0x1e02e43e <+300>: pushl 0x1e204f74 0x1e02e444 <+306>: call 0x1e02e248 => 0x1e02e449 <+311>: mov 0x4(%ebx),%eax 0x1e02e44c <+314>: pushl 0x1e204f74 0x1e02e452 <+320>: mov %eax,(%esi) 0x1e02e454 <+322>: mov %esi,0x4(%ebx) 0x1e02e457 <+325>: call 0x1e02e2eb 0x1e02e45c <+330>: add $0xc,%esp 0x1e02e45f <+333>: pop %edi 0x1e02e460 <+334>: mov %esi,%eax 0x1e02e462 <+336>: pop %esi 0x1e02e463 <+337>: ret End of assembler dump. (gdb) =========== script to reproduce the crash (attached too) === slightly modified pythonwin\pywin\Demos\ocx\webbrowser.py # This demo uses the IE4 Web Browser control. # It catches an "OnNavigate" event, and updates the frame title. # (event stuff by Neil Hodgson) import win32ui, win32con, win32api, regutil from pywin.mfc import window, activex from win32com.client import gencache import sys, os WebBrowserModule = gencache.EnsureModule("{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 0, 1, 1) if WebBrowserModule is None: raise ImportError("IE4 does not appear to be installed.") class MyWebBrowser(activex.Control, WebBrowserModule.WebBrowser): pass ## def OnBeforeNavigate2(self, pDisp, URL, Flags, TargetFrameName, PostData, Headers, Cancel): ## self.GetParent().OnNavigate(URL) ## #print "BeforeNavigate2", pDisp, URL, Flags, TargetFrameName, PostData, Headers, Cancel ##class BrowserFrame(window.MDIChildWnd): class BrowserFrame(window.FrameWnd): def __init__(self, url = None): if url is None: self.url = "http://www.google.com" else: self.url = url pass # Dont call base class doc/view version... def Create(self, title, rect = None): style = win32con.WS_VISIBLE | win32con.WS_OVERLAPPEDWINDOW ##style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_OVERLAPPEDWINDOW ##self._obj_ = win32ui.CreateMDIChild() self._obj_ = win32ui.CreateFrame() self._obj_.AttachObject(self) self._obj_.CreateWindow(None, title, style, rect, self) rect = self.GetClientRect() rect = (0,0,rect[2]-rect[0], rect[3]-rect[1]) self.ocx = MyWebBrowser() self.ocx.CreateControl("Web Browser", win32con.WS_VISIBLE | win32con.WS_CHILD, rect, self, 1000) self.ocx.Navigate(self.url) self.HookMessage (self.OnSize, win32con.WM_SIZE) def OnSize (self, params): rect = self.GetClientRect() rect = (0,0,rect[2]-rect[0], rect[3]-rect[1]) self.ocx.SetWindowPos(0, rect, 0) def OnNavigate(self, url): title = "Web Browser - %s" % (url,) print title self.SetWindowText(title) import pywin.mfc.thread class MyApp(pywin.mfc.thread.WinApp): frame = None def InitInstance(self): #$pycheck_no global f self.frame = f = BrowserFrame() self.frame.Create("Web Browser") if 'pywin.debugger' not in sys.modules: self.SetMainFrame(self.frame) if __name__=='__main__': ##win32ui.Enable3dControls() win32ui.EnableControlContainer() ##app = win32ui.GetApp() app = MyApp() app.InitInstance() ##f = BrowserFrame() ##f.Create("Web Browser") if 'pywin.debugger' not in sys.modules: ##app.SetMainFrame(f) print "Run() ..." ##app.Run() print "Run() terminated." ##f.DestroyWindow() ##print "f.DestroyWindow() 'ed." ##os._exit(0) -------------- next part -------------- A non-text attachment was scrubbed... Name: webbcrash.py Type: text/x-python Size: 2860 bytes Desc: not available URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: startframework.pyw URL: From kxroberto at googlemail.com Tue Dec 27 18:02:55 2011 From: kxroberto at googlemail.com (Robert) Date: Tue, 27 Dec 2011 18:02:55 +0100 Subject: [python-win32] Several, totally isolated Python interpreters in the same process In-Reply-To: References: Message-ID: Thomas Heller wrote: > I made an experiment that I wanted to share because it is imo kind > of cool: > > I managed to embed a second Python interpreter in a Python > process, with > help of WinSxS (WinSxS is a Microsoft technology that allows to > isolate > plugins from other plugins, or from the calling process). > > The second interpreter is totally isolated from the calling process. > > The idea is to use this technology to decouple COM extensions > implemented in Python from the caller and from other COM extensions. > But there may be other uses as well... > > The code is here: > > http://code.google.com/p/ctypes-stuff/source/browse/trunk/winsxs > is it necessary to have extra python files for each instance? or could one existing python installation run in multiple instances too this way ? Robert > > Information I found useful about WinSxS and assemblies: > > http://msdn.microsoft.com/en-us/library/dd408052%28v=VS.85%29.aspx > > http://omnicognate.wordpress.com/2009/10/05/winsxs/ > > > Thomas