Re: [python-win32] [ANN] pywin32 build 300 released
Thank you so much, Mark, and to everyone else who has contributed over the years. The build environment improvements will be especially welcome. regards, -Preston On Sat, Nov 14, 2020 at 12:31 AM Mark Hammond wrote: > > Hi all, >I'm happy to announce the release of pywin32 build 300. > Significantly, this is the first release to exclusively support Python 3 > - Python 2 is no longer supported. All Python source files in the repo > are now in Python 3 syntax. To celebrate, the build numbers have jumped > to 300 - there will not be a build 229. > > There were significant changes in this release - you are encouraged to > read the changes below carefully > > Downloads are available at: > >https://github.com/mhammond/pywin32/releases/tag/b300 > > and via pypi. > > For initial support (eg, to ask questions about the release etc), please > contact this mailing-list (python-win32@python.org). If you want to > report a bug, please do so at https://github.com/mhammond/pywin32/issues > > As always, thanks to everyone who contributed to this release, both in > terms of code and reporting bugs - there were a number of new > contributors which is great to see, > > Cheers, > > Mark. > ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] pure python way to open a file with write deny for others
Is advisory file locking an option? Such as the "portalocker" module for Python? You can have your writer process obtain an exclusive lock (and block until it's obtained), while the readers obtain shared locks for the duration of their read. Readers don't block other readers, while writers block both writers and readers. https://github.com/WoLpH/portalocker On Fri, Mar 6, 2020 at 10:51 AM Robin Becker wrote: > > On 05/03/2020 16:04, Eryk Sun wrote: > > On 3/5/20, Robin Becker wrote: > >> I want to be able to read a windows file which is being periodically > >> written > >> by another process. > > > > I'm having difficulty reconciling this sentence with the subject line. > > OK I want to read the (small) file completely. The other process may try to > re-write the file while I am reading it. I > thought that denying them write permission for the short time I have the file > open for reading might make incomplete > files less likely. So far the applications seem to be able to operate in this > fashion and the small files seem to be > complete. > > Of course the other process may adopt a completely orthogonal scheme of > opening with a different name and then renaming, > but I would then try to read the new version as its time stamp would change. > We have no access to the internals of the > writer and are just attempting to push textfile changes from a folder to a > server. Perhaps there's a better way to do that. > > > > If you want to open a file for reading that's already open for > > writing, then the open has to share write access, not deny it (where > > to "deny" access means to not share access) [1]. That's not an issue > > since Python shares read and write access when opening a file. (Note > > that the share mode applies to all opens. It is not related to > > processes, so whether it's another process or the current process > > that's writing to the file is irrelevant to the problem.) > > > > I wouldn't use FILE streams in Python 3. I'd pass an `opener` to > > Python `open` that uses ctypes or PyWin32 to get a handle via > > `CreateFileW`, and then msvcrt.open_osfhandle to wrap the handle with > > a C file descriptor. The opener function signature is opener(filename, > > flags) -> fd. > > > > [1]: > > https://docs.microsoft.com/en-us/windows/win32/fileio/creating-and-opening-files > > > > > -- > Robin Becker > ___ > python-win32 mailing list > python-win32@python.org > https://mail.python.org/mailman/listinfo/python-win32 ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Bug reporting
Bob, Is there are reason you can't use PyODBC? https://github.com/mkleehammer/pyodbc/wiki It is more actively maintained and I've used it successfully for years. I'm curious what adodbapi is doing for you that PyODBC can't? Are you using non-SQL data sources? thanks, Preston ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Python - connexion to serial port
You could have a worker thread or process that keeps the serial port open and listens for jobs on some kind of task queue. However it's not clear to me how keeping the serial port open between requests provides assurance of data integrity. On Thu, Jan 11, 2018 at 9:27 AM Schoeni, Yannwrote: > Hey there ! > > > > I’ve a web application which needs to send data to a serial port. The > webserver uses ajax to send data to a python script. > > > > The Python script uses the serial module to open, send data, and close the > serial port. > > > > *Is there a way to keep the serial port open ? * > > > > Because for now, I open/close it between each transaction and I need to be > 100% sure the data package will be send .. which is not the case with my > actual python script. > > > > Thank you in advance for your answer. > > > > Best wishes > > > > *Yann Schoeni* > > *Municipalité de Moutier * > > Apprenti informaticien > > Tél. +41 (0)32 494 11 69 <+41%2032%20494%2011%2069> > > Mob. +41 (0)79 827 30 86 <+41%2079%20827%2030%2086> > > E-mail yann.scho...@moutier.ch > > > ___ > python-win32 mailing list > python-win32@python.org > https://mail.python.org/mailman/listinfo/python-win32 > ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] os.remove not deleting a file
Generally, Windows won't let you delete a file if it's open somewhere, whether in the same process or in another process. You said the file becomes delete-able when you kill python, so I'm guessing that another part of your program (not shown) is holding the file open? You can always use something like Process Explorer [1] to determine exactly which process is holding a file lock. If it's your own Python program, look for a place that is doing a file open() call that is not using a context manager ("with" statement) or at least manually calling close(). If this block of code you showed is inside a "with open" call for that file, then that's the problem. [1] https://docs.microsoft.com/en-us/sysinternals/downloads/process-explorer On Sun, Nov 5, 2017 at 5:35 AM Henk Zevenhuizenwrote: > Hi there, > > This is my first mail to this list and i have a huge problem. > > my os.remove(filename) is not working. > > i am running python27 32 bits on a windows 10 64 bits machine > > My piece of code (with debugging statements): > > raw_input('before...') > print 73, (os.path.join(VERWERKTDIR, orgname)) > > if os.path.isfile(os.path.join(VERWERKTDIR, orgname)): > os.remove(os.path.join(VERWERKTDIR, orgname)) > raw_input('after...') > > print 'file removed' > else: > print 'no file present'' > > > if there is a file to be removed i can see the print 'file removed' > however the file is still there > > when i get the message : 'before' i can delete the file through windows > explorer and with CTRL-Z i can restore the file > then i press to continue the raw_input('before...') > > Then i get the message: "after", the file is still there and i cannot > delete the through windows explorer (permission denied) > the only way to delete the file is killing python > > I don't have the slightest idea where to look > > Has anyone any idea ?? > > thanks in advance > > Henk Zevenhuizen > Holland > > > > > > > ___ > python-win32 mailing list > python-win32@python.org > https://mail.python.org/mailman/listinfo/python-win32 > ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Equivalence of win32com.client under Linux
I wouldn't say it's 100% impossible - there is a thing called Mono which allows, subject to numerous limitations, running some .NET code on Linux. However it certainly wouldn't be the easiest path to take. I guess the question is why do you feel the need to run this code under Linux. It would be much easier to run the code on Windows, whether under a virtual machine inside a Linux host or on a separate host. And then write some bridge code - a network server or some other kind of communication channel - to communicate between the Linux process and the Windows one. It all begs the question of why you want to do this under Linux and what the real requirements are. On Thu, Mar 23, 2017 at 10:19 AM Brahim EL ALLIOUI <belalli...@gmail.com> wrote: > Thank you for the answer > > My goal is to interface a C# dll with python > At win32com.client I use just Dispatch and pythoncom, I think there is > probably an equivalent of these two components > > Is there a way to use a C# dll via python on Linux? > > I found in the net pypiwin32 but I can not install it and I do not know is > what it will meet my need or not > > > *Brahim EL ALLIOUI* > *General Manager* > belalli...@e-acta.com > Skype : belallioui > Tel : +212535749410 <+212%205357-49410> > Mobile : +212661940077 <+212%20661-940077> > www.e-acta.com > www.actaERP.com > > > 2017-03-23 14:06 GMT+00:00 Preston Landers <pland...@gmail.com>: > > Python-Win32 is code that works with "Win32" aka Microsoft Windows. > > Debian is a distribution of Linux, which is a completely different system > that is not compatible with Win32 code. > > The only thing to be done in Debian is install a virtual machine with > Windows inside. > > > On Thu, Mar 23, 2017 at 8:44 AM Brahim EL ALLIOUI <belalli...@gmail.com> > wrote: > > Hello, > > I use win32com.client to integrate a C # dll under python. This works well > under windows > > From win32com.client import Dispatch, pythoncom > From ctypes import cdll > Mydll = cdll.LoadLibrary (spath) > Pythoncom.CoInitialize () > Zk = Dispatch ("zkemkeeper.ZKEM") > > But do not works under unix > > What should you do at the Debian level? > Thank you > > *Brahim EL ALLIOUI* > *General Manager* > belalli...@e-acta.com > Skype : belallioui > Tel : +212535749410 <+212%205357-49410> > Mobile : +212661940077 <+212%20661-940077> > www.e-acta.com > www.actaERP.com > > ___ > python-win32 mailing list > python-win32@python.org > https://mail.python.org/mailman/listinfo/python-win32 > > > ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Inheritable sockets on Windows and multiprocessing
Thanks to Eryk Sun who pointed out that you can now just directly pass the socket object to the child process in multiprocessing (instead of the fileno int). I confirmed that worked for my use case. http://bugs.python.org/issue28906 thanks, Preston On Tue, Dec 6, 2016 at 5:11 PM Preston Landers <pland...@gmail.com> wrote: Hello, Please excuse me if this is not the appropriate forum. I'm porting a Python 2.6 based application to Python 3.6. This app uses a customized version of the "flup" package to do FastCGI services on Windows using the multiprocessing package. This requires a few sockets to be inherited across processes - the main FastCGI protocol socket plus a control socket. In Python 2.6, the `socket.from_fd` function was not available on Windows. However I patched Python's socketmodule.c to provide that function using DuplicateHandle. In Python 2.6's version of multiprocessing it spawned a process with CreateProcess and bInheritHandles=True. This worked beautifully for me. Now I'm trying to get this working after moving from Python 2.6 to 3.6. Fortunately, the socket module now has a working `socket.from_fd` on Windows so I no longer have to patch that. Unfortunately for me, though, the multiprocessing module now calls CreateProcess with bInheritHandles=False. This causes my scenario to fail. Here's a short test script which illustrates this problem: https://gist.github.com/Preston-Landers/712fee10fb557cf0b5592b57561a7c08 If you run with an unpatched multiprocessing, it will fail with an error like: OSError: [WinError 10038] An operation was attempted on something that is not a socket If you patch multiprocessing to set bInheritHandles=True this now works. (Change is in popen_spawn_win32.py where it does _winapi.CreateProcess.) I'm sure there's a good reason for that change in multiprocessing, whether for security or for unrelated/undesired file handles being passed. https://www.python.org/dev/peps/pep-0446/#inheritance-of-file-descriptors-on-windows However it does break my scenario and I don't see a way to tell multiprocessing to allow certain handles to be inherited. The docs for multiprocessing say "In particular, unnecessary file descriptors and handles from the parent process will not be inherited." It would be nice to have a way to tell it that my sockets are "necessary." You would think that calling socket.set_inheritable(True) would do it. In fact you must do that, but you must also pass bInheritHandles=True to CreateProcess for it to actually work. I do realize I could be going about this completely wrong, though. But right now it looks like my immediate options are: a) Go ahead and patch my copy of popen_spawn_win32.py to allow inherited handles. b) Try to rewrite things to not use multiprocessing at all and directly spawn my processes instead. That's not attractive because multiprocessing otherwise does what I need to do. Are there any other options I'm missing? thanks, Preston ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
[python-win32] Inheritable sockets on Windows and multiprocessing
Hello, Please excuse me if this is not the appropriate forum. I'm porting a Python 2.6 based application to Python 3.6. This app uses a customized version of the "flup" package to do FastCGI services on Windows using the multiprocessing package. This requires a few sockets to be inherited across processes - the main FastCGI protocol socket plus a control socket. In Python 2.6, the `socket.from_fd` function was not available on Windows. However I patched Python's socketmodule.c to provide that function using DuplicateHandle. In Python 2.6's version of multiprocessing it spawned a process with CreateProcess and bInheritHandles=True. This worked beautifully for me. Now I'm trying to get this working after moving from Python 2.6 to 3.6. Fortunately, the socket module now has a working `socket.from_fd` on Windows so I no longer have to patch that. Unfortunately for me, though, the multiprocessing module now calls CreateProcess with bInheritHandles=False. This causes my scenario to fail. Here's a short test script which illustrates this problem: https://gist.github.com/Preston-Landers/712fee10fb557cf0b5592b57561a7c08 If you run with an unpatched multiprocessing, it will fail with an error like: OSError: [WinError 10038] An operation was attempted on something that is not a socket If you patch multiprocessing to set bInheritHandles=True this now works. (Change is in popen_spawn_win32.py where it does _winapi.CreateProcess.) I'm sure there's a good reason for that change in multiprocessing, whether for security or for unrelated/undesired file handles being passed. https://www.python.org/dev/peps/pep-0446/#inheritance-of-file-descriptors-on-windows However it does break my scenario and I don't see a way to tell multiprocessing to allow certain handles to be inherited. The docs for multiprocessing say "In particular, unnecessary file descriptors and handles from the parent process will not be inherited." It would be nice to have a way to tell it that my sockets are "necessary." You would think that calling socket.set_inheritable(True) would do it. In fact you must do that, but you must also pass bInheritHandles=True to CreateProcess for it to actually work. I do realize I could be going about this completely wrong, though. But right now it looks like my immediate options are: a) Go ahead and patch my copy of popen_spawn_win32.py to allow inherited handles. b) Try to rewrite things to not use multiprocessing at all and directly spawn my processes instead. That's not attractive because multiprocessing otherwise does what I need to do. Are there any other options I'm missing? thanks, Preston ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Tkinter newbie
It's not unusual for people to think this list is for general discussion of Python for Windows people, rather than specifically for the PyWin32 package. On Tue, Mar 3, 2015 at 10:17 AM, Mark Lawrence breamore...@yahoo.co.uk wrote: On 03/03/2015 08:28, John Sampson wrote: I had spent a day trying to find a solution. Still, I know now one place I won't look for help. JS I don't understand why you've asked a tkinter question on a list targeted at Python on Windows. Either try the main python mailing list at https://mail.python.org/mailman/listinfo/python-list or gmane.comp.python.general, or the tkinter specific list at https://mail.python.org/mailman/listinfo/tkinter-discuss or gmane.comp.python.tkinter. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32 ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Tkinter newbie
Fair enough. What I was getting at is that sometimes people think because they happen to be using Windows this is a good place for general Python questions, rather than stuff that is Windows platform specific. Or in this case he may not have realized that tkinter isn't specific to Windows. On Tue, Mar 3, 2015 at 10:59 AM, Tim Golden m...@timgolden.me.uk wrote: On 03/03/2015 16:50, Preston Landers wrote: It's not unusual for people to think this list is for general discussion of Python for Windows people, rather than specifically for the PyWin32 package. That's because it is. From https://mail.python.org/mailman/listinfo/python-win32: All issues related to programming Python on Windows. win32 extensions, COM, you name it. TJG ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32 ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Using pip to install pywin32
I don't think pip can run this script (it even needs admin privs!). Is there a reason it couldn't run a script that presents a UAC prompt to elevate the process? Something like this: https://gist.github.com/Preston-Landers/267391562bc96959eb41 I guess for unattended installs you could just elevate the process beforehand. -Preston On Fri, Feb 20, 2015 at 9:24 AM, Thomas Heller thel...@ctypes.org wrote: Am 20.02.2015 um 15:07 schrieb Vernon D. Cole: Pywin32 is mostly written in C, and has lots of dependencies and weird build requirements. In order to compile it, you must have the same C compiler that your release of Python was built with. For older Python versions (like 2.7) that compiler is obsolete and hard to find, so installs from source are pretty nearly impossible. Would a binary wheel be able to do all of the crazy set up that the Windows installer does? AFAIK, wheel do not support post_install scripts. According to the comments in Scripts\pywin32_postinstall.py, it does: # copies PyWinTypesxx.dll and PythonCOMxx.dll into the system directory, # and creates a pth file According to the code, it does a lot more... I don't think pip can run this script (it even needs admin privs!). Thomas ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32 ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Using pip to install pywin32
Actually that gist wouldn't help much since it uses pywin32, the thing we're trying to install. (derp!) There may be another way though. Possibly related: http://bugs.python.org/issue20641 On Fri, Feb 20, 2015 at 10:31 AM, Preston Landers pland...@gmail.com wrote: I don't think pip can run this script (it even needs admin privs!). Is there a reason it couldn't run a script that presents a UAC prompt to elevate the process? Something like this: https://gist.github.com/Preston-Landers/267391562bc96959eb41 I guess for unattended installs you could just elevate the process beforehand. -Preston On Fri, Feb 20, 2015 at 9:24 AM, Thomas Heller thel...@ctypes.org wrote: Am 20.02.2015 um 15:07 schrieb Vernon D. Cole: Pywin32 is mostly written in C, and has lots of dependencies and weird build requirements. In order to compile it, you must have the same C compiler that your release of Python was built with. For older Python versions (like 2.7) that compiler is obsolete and hard to find, so installs from source are pretty nearly impossible. Would a binary wheel be able to do all of the crazy set up that the Windows installer does? AFAIK, wheel do not support post_install scripts. According to the comments in Scripts\pywin32_postinstall.py, it does: # copies PyWinTypesxx.dll and PythonCOMxx.dll into the system directory, # and creates a pth file According to the code, it does a lot more... I don't think pip can run this script (it even needs admin privs!). Thomas ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32 ___ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Failing to email large attachment with Python on Windows XP
On Thu, Feb 14, 2013 at 12:06 PM, Tim Roberts t...@probo.com wrote: newtechnologybooks wrote: /I was able to deliver 20mb files with this script, but failed when //trying 100mb files. / That's further evidence that you have hit a server limit. If you want to send 100MB files, you store them on an FTP server or a web server and send a link. Companies do not want 100MB attachments clogging up their mail pipe and bulking up their mail store. On my network sniffer I don't see any evidence that the code has start sending any kind of data to the sever, it just hang for a few seconds till the client send a FIN flagged packet to the server. Is it possible that it's simply taking too long to read and/or encode the attachment? That seems like a long-shot, but you're kind of at the long-shot phase now. I also wonder if he's got some kind of antivirus or security scanner intercepting things and getting hung up. I've seen it before. ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] building pywin32 for python 2.6...
I thought you had to have Visual Studio 2008 to build Python 2.6 and extensions. You might want to confirm that VS 2010 is supported for the releases you're using. Failure to find vcvarsall.bat can be caused if you're trying to run this from a regular windows command line. Try launching the Visual Studio version of command prompt. It should set the paths to let you find vcvarsall. Good luck, Preston On Wed, Jan 30, 2013 at 8:29 AM, SEIGAL Nick nsei...@lcog.org wrote: I am trying to get pywin32 build 218 installed and am having trouble. Here is the error I am getting: C:\Python26python F:\Downloads\Python\pywin32\pywin32-218\setup.py install Building pywin32 2.6.218.0 running install running build running build_py running build_ext Found version 0x601 in C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\SDKDDKVER.H building 'perfmondata' extension C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\mc.exe -h win32\src\perfmon -r build\temp.win32-2.6\Release\win32\src\ perfmon win32\src\perfmon\PyPerfMsgs.mc MC: Compiling win32\src\perfmon\PyPerfMsgs.mc C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\rc.exe /fobuild\temp.win32-2.6\Release\win32\src\perfmon\PyPerfMsgs.re s build\temp.win32-2.6\Release\win32\src\perfmon\PyPerfMsgs.rc Microsoft (R) Windows (R) Resource Compiler Version 6.1.7600.16385 Copyright (C) Microsoft Corporation. All rights reserved. C:\Program Files\Microsoft Visual Studio 10.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DDISTUTILS_BUILD -D_CR T_SECURE_NO_WARNINGS -Icom/win32com/src/include -Iwin32/src -IC:\Python26\include -IC:\Python26\PC -IC:\Program Files\M icrosoft SDKs\Windows\v7.0A\include /Tpwin32\src\perfmon\perfmondata.cpp /Fobuild\temp.win32-2.6\Release\win32\src\perf mon\perfmondata.obj /Zi /Fdbuild\temp.win32-2.6\Release\perfmondata_vc.pdb /EHsc /DMFC_OCC_IMPL_H=\..\src\occimpl.h\ / DUNICODE /D_UNICODE /DWINNT perfmondata.cpp win32\src\perfmon\perfmondata.cpp(11) : fatal error C1083: Cannot open include file: 'perfutil.h': No such file or direc tory error: command 'C:\Program Files\Microsoft Visual Studio 10.0\VC\BIN\cl.exe' failed with exit status 2 I had followed a forum suggestion to set a VS90COMNTOOLS environmental variable to my VS2010 VS100COMNTOOLS value like this: SET VS90COMNTOOLS=%VS100COMNTOOLS% Prior to doing that, I couldn’t even get past an Unable to find vcvarsall.bat error. As you can probably tell, I am installing on Windows (XP Pro SP 3) and have Python 2.6.5 and Visual Studio 2010 (full version). Any suggestions? Nick Seigal - Senior GIS Analyst/Application Developer - Lane Council of Governments 859 Willamette Street, Suite 500 - Eugene, Oregon 97401-2910 (541) 682-6733 - (541) 682-4099 (fax) - www.lcog.org Messages to and from this e-mail address may be subject to disclosure under Oregon Public Records Law. þ Please consider the environment before printing this message. ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] DIR reports file timestamp and size, but os.path.getctime(), os.path.getsize() raise WindowsError [Error 5] Access is denied
I'm guessing Microsoft set some unusual ACLs on the files for security reasons. Have you looked at the advanced security options for these files in Windows Explorer? Have you tried running the script as Administrator? If you don't really care about the files you can skip them. If for some reason you absolutely have to retrieve that info, you could try tweaking the ACLs or maybe try launching a dir process and parse the output. -Preston ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Passing an object to a process
Without getting into too philosophical of a discussion, the only sense in which objects can truly move from one process to another is recreating them in the other process. Even fork() makes copies of everything. Have you tried pickle or other techniques of serialization? Not sure offhand if the logger module supports pickle but it might. You can always just create a new logger object using the same parameters as the original (filename, etc), right? Or am I missing something? There IS a way to get filehandles to be shared by a child process. But do you even need to do that if you can just recreate a new logger object? regards, Preston On Wed, Mar 14, 2012 at 1:53 PM, Tony Cappellini cappy2...@gmail.com wrote: On Windows XP - I've got a program running which has spawned a process using os.spawnv(). My program has a logger object instantiated that I want to pass to the process that was spawned. I need to log errors seen by the process, to the same logfile that the program uses for logging. I have the handle, thread ID, and process id of the process, but I see no way to share the logger object using these values. How can I pass a logger instance to the process, from the program which spawned the process? For legacy compatibility reasons, I'm stuck with an older version of Python that doesn't have the subprocess module and other features that are available with more modern releases of Python. ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Passing an object to a process
On Wed, Mar 14, 2012 at 2:55 PM, Tony Cappellini cappy2...@gmail.com wrote: in which objects can truly move from one process to another is recreating them in the other process. Even fork() makes copies of everything. Recreating an object in another process means it's a different object, not a shared one. Yeah, I know. I was trying to make that point. There's no real way for the same object to exist in multiple processes other than SYSV shared mem. Truly shared memory (i.e, SYSV style) is tricky, not very portable, and usually the wrong answer in my experience. As fas as I know stock Python doesn't support that, and definitely never will on Windows. The point is that you need to figure out what problem you're really trying to solve (logging to one file from multiple processes, it sounds like) and then find the best / simplest approach, which I can tell you definitely doesn't involve SYSV shared memory. It's probably just creating separate logging objects in each process, pointing to the same file, and protected by file locking if necessary. Have you tried pickle or other techniques of serialization? Not sure offhand if the logger module supports pickle but it might. Yes. I've just tried this, even though I expected it not to work. If process A pickles a logger object, and process B unpickles it, referencing of an object in a different process is meaningless. In my case, when the process attempted to write to the logger, no entries were seen in the logfile. Surprisingly, no exceptions occurred- but this could just be a coincidence. Probably because the logger object, when serialized, saves a reference to an open filehandle, which won't be automatically transfered to the other process. (There might ultimately be a way to make that work by inheriting filehandles, but again, if you can find something simpler...) That may work, and with less effort than my original idea. But if two processes write to the logfile at the same time (especially on a multicore machine), hard-to-read logfiles may result. it's worth a try. Yes, that type of thing can occur, but you can also get around that with simple file locking. By the way, that same problem certainly exists even if you somehow shared the object between two processes - what if the two processes made a log call at the same time? File locking may introduce some performance issues if the logging is very frequent, but usually you can find ways to mitigate that. The main app I work on uses log files extensively, and the same file is appended to by unrelated processes without a locking mechanism. Occasionally you do see some interleaving of log entries but in my experience it's fairly rare and in my particular case we don't care much about that anyway. regards, Preston ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Issuing a command via subprocess, other methods in Windows 7
I thought start wasn't an actual executable but rather a builtin command of the cmd.exe shell. Have you tried something like: scope = subprocess.Popen([r'cmd.exe', '/c start SoundRecorder'],shell = True, stdout=subprocess.PIPE) regards, Preston On Wed, Feb 22, 2012 at 1:09 AM, David Hutto smokefl...@gmail.com wrote: Hi, I'm using: Microsoft Windows [Version 6.1.7600](Windows 7) Copyright (c) 2009 Microsoft Corporation. All rights reserved. Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on win32 I've tried numerous methods trying to send a simple command in a shell session. When the commands are placed into the windows command prompt directly, they issue perfectly fine, but in the below interpreter session errors, it finds and utilizes START, as well as other shell commands, but not for other types of primary commands that work when typed directly int the windows command prompt, such as SoundRecorder(shown below). Below are a few of my unlucky attempts: scope = subprocess.Popen([SoundRecorder],shell = True, stdout=subprocess.P IPE) 'SoundRecorder' is not recognized as an internal or external command, operable program or batch file. scope = os.system(START, SoundRecorder) The system cannot find the file SoundRecorder. scope = subprocess.Popen([r'START', 'SoundRecorder'],shell = True, stdout=su bprocess.PIPE) The system cannot find the file SoundRecorder. scope = subprocess.Popen([r'START', 'C:\Windows\System32\SoundRecorder.exe'],she ll = True, stdout=subprocess.PIPE) The system cannot find the file C:\Windows\System32\SoundRecorder.exe. Just using START, like below: scope = subprocess.Popen([r'START',shell = True, stdout=subprocess.PIPE) initiates the START command, which means it works, but not on command line when using SoundRecorder which is in the system32 dir. I thought it might be a directory placement problem, but don't know if that would be the correct way to fix it, or if that's even the problem. Any ideas why the above works for the START, and not the SoundRecorder, when both work on the windows command prompt when typed directly in? Thanks, David ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] encoding decoding for python2.5
Hi, I think people might be reluctant to give you an in-depth tutorial here on security and encryption. For one thing it's not really the right place - this is the mailing list for the PyWin32 extensions and related topics, not for the general topic of securing information in databases. Also it's pretty clear that you're a bit of a neophyte at this (no offense intended, it may also be a language issue) so people might be reluctant to give you simple advice (one or two paragraph's worth) and then you might get a false sense of security that you've got the security issue handled. Securing a web app is a complex process and it involves way more than simply encoding a few fields. Personally, I would focus on securing overall access to your database instead of trying to secure particular fields within the database. I wouldn't recommend giving untrusted users direct access (even read-only) to a production database like this. I would mediate everything through access controls in my web app. If you still want to encrypt fields, there's packages out there like PyCrypto you can investigate. MySQL also seems to contain some encryption functions though I'm not personally familiar with them. Good luck, Preston On Wed, Sep 28, 2011 at 1:22 PM, ad3d alhaddeshpa...@gmail.com wrote: Dude, i was just trying to develop a software in which some sensative data like employee salary are stored..so for the data security purpose i was trying to find a way out... i tried using chilkat but its full version is not available..thats why i was trying for some help on this topic..i am using MySQL as database..and using python2.5 and all the fields i am trying to store are strings..no one should be able to view salaries or review information of employees from database tht was d agenda.. Thanx ad3d Vernon Cole-3 wrote: Dear person: There are lots of ways to encode and decode data. You'll need to provide some more information about the use you intend in order to get good advise. Do you just want to protect something from prying eyes on one workstation? How secure does it have to be? Are you sending the data to someone else, who must then decode it? Is it in some compressed format (like audio or picture) and you need to read and write it? Are you perhaps a terrorist with whom we prefer not to share information about cryptography, and thats why you don't have a name? Or do you only want to change a character string from one encoding to another? Provide more details, please. -- Vernon On Fri, Sep 23, 2011 at 12:49 AM, ad3d alhaddeshpa...@gmail.com wrote: Hi Guys, I want to encode and decode some data using python 2.5. can someone plz suggest me some algorithms(freeware not trial version) for the same.. thanx in advance -- View this message in context: http://old.nabble.com/encoding-decoding-for-python2.5-tp32503855p32503855.html Sent from the Python - python-win32 mailing list archive at Nabble.com. ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 -- View this message in context: http://old.nabble.com/encoding-decoding-for-python2.5-tp32503855p32549609.html Sent from the Python - python-win32 mailing list archive at Nabble.com. ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] UnicodeEncodingError when print a doc file
I think you'll have to get into the guts of the Document object to do things like that. Here's the official Word 2007 object model documentation. Any tutorials or examples you can find that use other languages like C# or VB.NET would be relevant, you just have to translate them a bit to Python. The underlying Document API is the same across languages. http://msdn.microsoft.com/en-us/library/bb243297(v=office.12).aspx On Tue, Jun 14, 2011 at 8:20 PM, cool_go_blue cool_go_b...@yahoo.comwrote: Thanks. I just find that all item numbers such as 1.1.1 are gone. How can I get these numbers. Also, If all items are in a table, how can I get the contents of all items and ignore the table structure. Thanks. ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Trying to get py2exe to install/work on my windows7 64 bit machine
Looks like you downloaded the 64 bit version of py2exe but are trying to use it with the 32 bit version of Python. Either get the 64 bit version of Python 2.7, or else the 32 bit version of py2exe. good luck, Preston On Wed, Jun 1, 2011 at 11:24 AM, Jacob Kruger jac...@mailzone.co.za wrote: When I try installing: py2exe-0.6.9.win64-py2.7.amd64.exe It tells me: Cannot install Python version 2.7 required, which was not found in the registry. Any thoughts/suggestions? When I ran: pywin32-216.win32-py2.7.exe it was quite happy to install to c:\python27 Have tried restarting machine, etc., and can't remember if ran some other scripts on my windows7 32 bit machine before it worked, but anyway. Stay well Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Python and registry access with UAC enabled
Not sure if this solves the actual problem you're having, but I wrote a small script to relaunch a process as an admin using UAC. Hopefully this helps somehow. http://dl.dropbox.com/u/11450437/pyuac.py thanks, -Preston On Mon, Apr 25, 2011 at 8:45 PM, Michael ODonnell odonn...@yahoo.comwrote: I have recently migrated to windows 7 from Windows XP. My organization enables UAC (level 3) at the group policy level and therefore I cannot disable it. I would like to know where there is a method to make registry changes using a python script without disabling UAC. For example, I can read registry hives and keys but I cannot write to them: import _winreg # Successful read RegConn = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE) keyStr = r'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\1033' key = _winreg.OpenKey(RegConn, keyStr, 0, _winreg.KEY_READ | _winreg.KEY_WOW64_32KEY) print _winreg.QueryValueEx(key, Version)[0] # Unsuccessful write x = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE) y = _winreg.OpenKey(x, rSYSTEM\CurrentControlSet\Control\Session Manager\Environment, 0, _winreg.KEY_ALL_ACCESS) _winreg.SetValueEx(y, path, 0, _winreg.REG_EXPAND_SZ,path + ;C:\\test) _winreg.CloseKey(y) _winreg.CloseKey(x) I have compiled my code as an EXE and created a manifest and using the trustinfo xml node, but this will also not work for me. I am always logged in as an administrator. Can anyone provide me with some suggestions on how I can work through this. Also, on a personal Windows 7 64bit machine, if I disable UAC, I can successfully write to the registry. Thank you, Mike ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Missing methods from result of Dispatch or EnsureDispatch
On Fri, Feb 25, 2011 at 1:14 PM, Parand Tony Darugar tdaru...@yahoo.comwrote: - Outside of Ironpython, is there a reasonable way to interaction with .Net objects/assemblies in Python? I haven't worked with it myself, but it looks like this is an option: http://pythonnet.sourceforge.net/ thanks, Preston ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Problem using win32com.client.Dispatch on Win7 64bit
The main use I've found for 64 bit Python is for running the Python ISAPI stuff under the IIS web server on 64 bit Windows. I guess technically that falls under using 64 bit COM objects. That and it helps when you need to open 4 GB files and use 2GB memory in a process. regards, -Preston On Fri, Oct 15, 2010 at 6:45 PM, Mark Hammond mhamm...@skippinet.com.auwrote: On 16/10/2010 6:23 AM, Eileen Wei wrote: Thanks Mark, that solved the problem. But I am wondering since 32bit Python and pywin32 work on 64bit machine, why do we need the 64bit version? - I have always thought that you need to install 64bit version on 64bit machines... In practice, it is rare you need the 64bit version - only if you need access to 3/4 GB of memory, need to use existing 64bit COM objects, etc. Cheers, Mark ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] PyWin32 sur intel xeon 64-bit
On Tue, Jul 20, 2010 at 8:04 AM, Pro bruno.lehya...@gmail.com wrote: Hi every body, I'm migrating from windows 32bit to 64bit on intel platform. I wonder if PyWin32 works well on intel 64 bit? Is somebody in the same case here? Regards, Bruno. Keep in mind that PyWin32 is the name of the product / package, but it can be deployed in both 32 bit and 64 bit configurations. In general, using a 32 bit Python + PyWin32 works just fine on 64 bit Windows. However there are a couple of very specific things that require a 64 bit build of Python and PyWin32 (and any other extensions) when running on a 64 bit server. One is running an ISAPI web server extension like iis_wsgi. (Running iis_wsgi may also require a tweak to Python 2.6.5's extension compiling file to fix the inclusion of Visual C runtime in the DLL manifest, but that's a bug/issue in Python, not PyWin32.) The other (I'm not 100% certain about this) is writing a Windows Explorer extension in Python. There may be a few other odds and ends like that which require 64 bit, but if you don't use / need those features, then you don't need to have 64 bit Python. I haven't seen any problems resulting from 64 bit deployment. It works great for me. Hope this helps, Preston ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] unable to read mssql varchar(max)
varchar(max) columns are like CLOBs, character large objects, and I'm not sure how well that odbc module handles them. I ended up switching to pyODBC which does handle them. Unfortunately it might not be just a drop-in replacement, and pyODBC does have its own issues. But so far it's working pretty well for us. http://code.google.com/p/pyodbc/ On Thu, May 27, 2010 at 10:56 AM, John j...@saponara.net wrote: Hi, When a ms sql server database column was changed to varchar(max), my python code became unable to read that column. no matter the actual value, python sees it as '\x00'. I use sql server 2008, python 2.4, and pywin32-214. it had worked when the column was a fixed size varchar, eg varchar(1000). essentially my code is: connectionString=rdriver={SQL Server Native Client 10.0};server=...;uid=...;pwd=...;database=... connection=odbc.odbc(connectionString) cursor=connection.cursor cursor.execute(select ...) cursor.fetchall() Could anyone suggest what the problem might be? Thanks, John ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] problems with subprocess module and env parameter
Your PATH is a Unicode string. I'm not sure offhand if that's acceptable or not, but all the rest of the strings appear to be regular (non-unicode) strings. You could also try: import types for k, v in env.iteritems(): if type(v) is not types.StringType: print k, v hope this helps, -Preston On Thu, Apr 15, 2010 at 3:40 PM, Bill Janssen jans...@parc.com wrote: When I call subprocess.Popen(), I'm getting an error from what I believe is win32process.CreateProcess: Traceback (most recent call last): File TestAdds.py, line 950, in testNoPasswordNoGuardian (UPLIB_MAKE_REPOSITORY, self.port, self.directory)) File TestAdds.py, line 96, in runSubProc env=env, shell=(sys.platform != win32)) File c:\Python26\lib\subprocess.py, line 633, in __init__ errread, errwrite) File c:\Python26\lib\subprocess.py, line 844, in _execute_child startupinfo) TypeError: environment can only contain strings I hacked my subprocess.py to print out the env argument, and here it is. I can't see anything wrong with it, but maybe some one else can. Bill -- env is { 'TMP': 'C:/DOCUME~1/wjanssen/LOCALS~1/Temp', 'COMPUTERNAME': 'MMM', 'HISTFILE': 'C:/msys/1.0/home/wjanssen/.bash_history', 'USERDOMAIN': 'MMM', 'MSYSFGCOLOR': 'Black', 'COMMONPROGRAMFILES': 'C:\\Program Files\\Common Files', 'PROCESSOR_IDENTIFIER': 'x86 Family 6 Model 15 Stepping 6, GenuineIntel', 'LOGNAME': 'wjanssen', 'PROGRAMFILES': 'C:\\Program Files', 'PROCESSOR_REVISION': '0f06', 'MSYSCON': 'rxvt.exe', 'HOME': 'C:/msys/1.0/home/wjanssen', 'DISPLAY': ':0', 'MAKEFLAGS': 'w', 'MSYSTEM': 'MINGW32', 'MAKE_MODE': 'unix', 'TERM': 'msys', 'COLORFGBG': 'default;default', 'UPLIB_VERBOSITY': '0', 'TEMP': 'C:/DOCUME~1/wjanssen/LOCALS~1/Temp', 'SHLVL': '2', 'PROCESSOR_ARCHITECTURE': 'x86', 'ALLUSERSPROFILE': 'C:\\Documents and Settings\\All Users', 'WINDOWID': '167838880', 'SESSIONNAME': 'Console', 'HOMEPATH': '\\', 'JAVA_HOME': 'C:\\Program Files\\Java\\jdk1.6.0_18', 'MFLAGS': '-w', 'FGCOLOR': 'Navy', 'USERNAME': 'wjanssen', 'LOGONSERVER': 'MMM', 'PROMPT': '$P$G', 'COMSPEC': 'C:\\WINDOWS\\system32\\cmd.exe', 'SYSTEMROOT': 'C:\\WINDOWS', 'MINGW32BGCOLOR': 'LightYellow', 'PATH': u'c:\\UpLib\\1.7.9\\bin:c:\\UpLib\\1.7.9\\bin;c:\\UpLib\\1.7.9\\Scripts;c:\\Python26;c:\\Python26\\Scripts;.;C:\\msys\\1.0\\local\\bin;c:\\mingw\\bin;C:\\msys\\1.0\\bin;c:\\Program Files\\WinAnt\\bin;c:\\Program Files\\MiKTeX 2.8\\miktex\\bin;c:\\WINDOWS\\system32;c:\\WINDOWS;c:\\WINDOWS\\System32\\Wbem;c:\\Program Files\\WinAnt\\bin;C:\\Program Files\\Java\\jre6\\bin\\client', 'BGCOLOR': 'LightYellow', 'UPLIBRC': 'C:\\msys\\1.0\\home\\wjanssen\\uplib\\tests\\tests\\tests.uplibrc', 'PATHEXT': '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH', '_': 'C:/msys/1.0/bin/make', 'MSYSBGCOLOR': 'White', 'FP_NO_HOST_CHECK': 'NO', 'UPLIB_LIB': 'c:\\UpLib\\1.7.9\\lib\\UpLib-1.7.9', 'MINGW32FGCOLOR': 'Navy', 'HOMEDRIVE': 'C:', 'APPDATA': 'C:\\Documents and Settings\\wjanssen\\Application Data', 'ANT_HOME': 'C:\\Program Files\\WinAnt', 'OLDPWD': 'C:/msys/1.0/home/wjanssen/uplib', 'NUMBER_OF_PROCESSORS': '1', 'MAKELEVEL': '2', 'PWD': 'C:/msys/1.0/home/wjanssen/uplib/tests', 'PROCESSOR_LEVEL': '6', 'COLORTERM': 'rxvt-xpm', 'USERPROFILE': 'C:\\Documents and Settings\\wjanssen', 'OS': 'Windows_NT', 'SYSTEMDRIVE': 'C:', 'WINDIR': 'C:\\WINDOWS'} ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] zip of file using python
If you plan to do a lot of ZIP file creation from Python, it's usually a whole lot faster, and may produce smaller files, if you call out to an external utility to do the compression instead of doing it from within the Python zipfile module. You can also pass compression arguments like -9 that produce smaller files. A while back I wrote a wrapper around zipfile that can call out to the external program if available, otherwise it falls back on using internal zipfile. I can send that to you or post it here if it would help you. regards, -Preston On Thu, Apr 8, 2010 at 4:53 AM, a h ah.k...@gmail.com wrote: thanks... i tried compression as zipfile.ZIP_DEFLATED and it works fine. Now i used WinRar software to compress a 1.5GB file, it results into a 42MB file where as using my script it results into 62 MB file. Is it because of different format, if so, is there any winrar lib or equivalent lib for python. ah On Thu, Apr 8, 2010 at 2:56 PM, Werner F. Bruhin werner.bru...@free.frwrote: On 08/04/2010 09:52, a h wrote: hi I want to zip a folder using python script. I have written below piece of code, but i found that total size of all file is equal to the size of resultant zip file. so no compression is done. Its just put all the files in a folder and say save it with an extension(.zip). May be i am wrong someway, but i checked it correctly. import zipfile, os archive_list = os.listdir(logs_21-01-2010) # save the files in the archive_list into a PKZIP format .zip file zfilename = logs_21-01-2010_.zip zout = zipfile.ZipFile(zfilename, w) I guess/think you need to define compression, see the doc for: 12.4.1 ZipFile Objects class ZipFile(file[, mode[, compression[, allowZip64]]]) e.g. zipfile.ZipFile('afile.zip', w, zipfile.ZIP_DEFLATED) Werner ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] MSI installer or zip file for pywin32?
You can run unzip on the official exe installer to get a directory structure that you can copy into your build. The pywin32_postinstall.py stuff is separated out in the arhcive, and does need to be run to enable all features. Depending on what you're doing you might be able to skip all or most of it. As far as the system DLLs, last time I checked they do have to be in the system32 directory (or the wow64 version.) But I could be wrong - I didn't play with that very much. If it works without installing system DLLs I'd be curious to know. regards, -Preston On Fri, Apr 2, 2010 at 8:13 PM, Bill Janssen jans...@parc.com wrote: Howdy, all. I'm writing a build script for UpLib on Windows with msys, and I'd like to find some way of installing the Python win32 extensions without running the old-style installer it currently comes with. Ideally, I'd like to just unpack the code and DLLs in my install directory, for later installation by my UpLib MSI installer. Is there any easy way to create such a simple package -- an MSI installer, or perhaps a tar or zip file? I'm working with Python 2.6 and MinGW/msys on Windows XP. Looking through pywin32_postinstall.py, I don't think I'll need most of it -- my python is captive under the UpLib directory, and only used by UpLib. I'd prefer not to install the pywin32 dlls in the C:\Windows\SYSTEM32 folder if possible; I'll just put them with the other UpLib DLLs. I won't need fixup_dbi(). No shortcuts. Bill ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] I/O error
Your indentation is a bit hard to read in this format, but it looks like the for subkey in uninstall block needs to be inside the with open block. When the with open block exits, the file is no longer open. Thus writing to a closed file will fail. On Mon, Mar 22, 2010 at 4:22 PM, travel europe europe_tra...@hotmail.comwrote: Hello, I am getting the following error ValueError: I/O operation on closed file when running a module to pull data from the Windows registry. The code is as follows: code import csv from winsys import registry key = rHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall fields = [DisplayName, Comments, InstallDate] # add to as required uninstall = registry.registry (key) with open (installed.txt, wb) as f: writer = csv.writer (f) writer.writerow (fields) for subkey in uninstall: info = dict (subkey.values ()) writer.writerow ([info.get (field) for field in fields]) code error message The error message is as follows: Traceback (most recent call last): File C:\Python26\tim.py, line 13, in module writer.writerow ([info.get (field) for field in fields]) ValueError: I/O operation on closed file error message Any ideas on how to rectify this problem? Thanks! -- Hotmail is redefining busy with tools for the New Busy. Get more from your inbox. Sign up now.http://www.windowslive.com/campaign/thenewbusy?ocid=PID27925::T:WLMTAGL:ON:WL:en-US:WM_HMP:032010_2 ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
[python-win32] odbc module and Unicode string literals
Hello all, I'm curious why the odbc module included in PyWin32 (version 214) is compiled without the Unicode flags/defines. This prevents you from using Unicode string literals in queries. By that I mean the Unicode literals are converted to the 8-bit codepage (cp1252) and any untranslatable characters are replaced with ?. Unicode works ok in bind variables, just not as literals in the main query. That is, unless I set the Unicode flag to True for odbc in PyWin32 setup.py around line 1441. Then the resulting odbc module seems to handle Unicode literals just fine. The test script included below should demonstrate that. The ADO module (adodbapi) doesn't have this issue - Unicode literals work ok. But it suffers from a few other problems, the most basic one is a performance gap of 25-30% compared to ODBC even after I generated the bindings with makepy. I assume this is due to general COM overhead. I can compile my own odbc module with the Unicode flag but I'm curious if there was a reason it was turned off to begin with. Maybe I'm missing something or would run into trouble later if I did that. thanks, -Preston # Note: the goal should be to get unicode intact twice. # First time is using a bind variable, second time is a string literal. # This assumes SQL Server backend - string literals are prefixed with N import odbc # Change to suit your server CONNSTR = dsn/username/password db = odbc.odbc(CONNSTR) cursor = db.cursor() # This has some extra-wide characters (surrogate pairs) testStr = u\u0669(\u0361\u0e4f\u032f\u0361\u0e4f)\u06f6 .\U0002a5ab\U0001d122\U00024b00 def query(sql, params): cursor.execute(sql, params) recs = cursor.fetchall() print repr(sql), repr(params) print repr(recs) if recs[0][0] == testStr: print unicode intact. else: print unicode did not survive round trip print return recs # Test as bind variable query1 = select ? as 'test' query(query1, [testStr]) # Test as straight Unicode literal query2 = select N'%s' as 'test' % (testStr,) query(query2, []) ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Problem accessing GetFontData in Windows API
I'm trying to access the following function from the Windows API: http://msdn.microsoft.com/en-us/library/dd144885(VS.85).aspx I'm sure I'm drastically over simplifying, but I'm testing it like this: import win32api print win32api.GetFontData() This of course errors out with AttributeError: function 'GetFontData' not found. I'm not 100% sure but I think you're going to need to use ctypes to call that. It's a little complicated but this may help: http://python.net/crew/theller/ctypes/tutorial.html from ctypes import * windll.gdi32 WinDLL 'gdi32', handle fe34 at 27b4cc0 windll.gdi32.GetFontData _FuncPtr object at 0x0273B2B8 ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] python-win32 Digest, Vol 81, Issue 13
On Sun, Dec 13, 2009 at 5:00 AM, python-win32-requ...@python.org wrote: Do you have evidence that your Python code is running in multiple threads? I.e. are you sure this isn't just ISAPI running some cleanup work in another thread? Oh yes. There was no doubt. I used a debugger (pydevd) to put a breakpoint at the start of each request. And then ran a section of my app which uses a frameset after limiting the app pool to 1 process. This caused several more or less simultaneous requests. The debugger showed the separate threads with the Dummy-# name label assigned by the Python threading module (plus MainThread) and I could switch back and forth between them in the debugger. I was also seeing other behavior consistent with threaded execution; there are some singleton guards in my app that were getting triggered. I also verified w/o the debugger by having each request log the thread ID via threading.currentThread() as well as the process ID. Everything I've read on ISAPI recently says it's always potentially multithreaded and that extensions must be prepared to run threaded e.g. by locking sensitive objects. At least in my case this wouldn't have been a problem if each thread ran in a separate interpreter (i.e, with separate copies of all modules.) Well, except for any un-thread-safe C extensions and GIL performance issues. For now I am using a thread lock to force sequential behavior within a process and using a multi-process application pool to achieve concurrency. thanks, -Preston ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] ISAPI and threading
On Mon, Dec 7, 2009 at 5:35 PM, Mark Hammond mhamm...@skippinet.com.au wrote: On 8/12/2009 9:45 AM, Preston Landers wrote: Someone had mentioned needing to restrict the worker pool to a single thread but indicated they didn't know how to do that. I searched around MSDN and couldn't find anything relevant. I also checked the PyWin32 ISAPI code and didn't see anything that appeared to start a new thread. Does anyone know how to force single threading in this scenario? Finding out where the thread was created should be your first goal. You are correct that pywin32's ISAPI support doesn't create threads except when establishing that thread-pool - which only happens when you explicitly sub-class that threaded implementation. As far as I can tell the threads are created directly by the ISAPI framework without reference to any Python/ISAPI code. They just make a new C thread then call the extension function without further ado. I tried to dig into it a little deeper by compiling a debug version of Python/PyWin32 (x64) but ran into some problems. Everything worked great with my debug build from the command line, including PyWin32 stuff and installing the ISAPI vdir. But when it came to actually running the code through IIS I got mysterious 500 server errors. They appeared very similar to the errors I got when I tried to use a 32 bit version of Python/ISAPI with 64 bit IIS despite setting the 32 bit app pool flag. (By the way, it might be good to note somewhere in the docs that you can't do that, if it doesn't already.) I think it's a generic DLL could not load type error but even with the IIS error tracing feature it wasn't very clear. I thought that maybe you also need a debug build of Windows/IIS itself for that to work, but that doesn't sound right. It's possible that since I'm running that debug build right out of the source dir I failed to register it properly or something. Anyway, even if I could identify where the thread was getting created and insert some code there I'm not even sure what it would do. I think forcing each thread to have a different Python interpreter might help. Some other Python web server packages like mod_python seems to do this. But for now I've opted for a simple lock in my WSGI handler function to bypass the whole issue. But I'm a little curious about the purpose of having a WSGI thread pool implementation in light of those facts. If ISAPI will create threads for you anyway, how does a pool help? Is it purely to avoid thread startup overhead? If a thread is being created anyway, you're just adding it to a queue to be handled by a separate thread from the pool. Seems like more overhead, not less. But I'm probably missing something there. Nor have I done a hands on performance test. The other option is just to use a lock - create a global lock object and have every request acquire it and release it when done. You should then find only 1 thread is ever actually running in your code while the rest are blocked waiting for the lock. As noted above though, this may severely impact performance... Yeah I went ahead and used a lock and it does fully resolve the issue. I'm hoping to avoid or at least mitigate any performance impact by having multiple worker processes configured automatically. IIS does seem to distribute the load pretty evenly in most cases. It will be a while before I have time to run some serious performance / stress tests, but when I do I will be testing a number of different scenarios. Even with the lock, so far performance seems far better than the prior solution we have, which is a byzantine combination of Classic ASP Python calling out to external app servers over a proprietary FastCGI-like socket protocol. Anyway, thanks for your input on this issue and all of your other excellent work. It's much appreciated. -Preston ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Options for running Python under IIS?
On Thu, Nov 12, 2009 at 6:32 AM, Mark Hammond skippy.hamm...@gmail.com wrote: On 12/11/2009 10:03 AM, Preston Landers wrote: 4) Use isapi-wsgi: This seems to be getting more popular but it seems to use threads and I'm wondering whether this will break my app in subtle ways. Thread support should be optional - it is if you use the lower-level isapi stuff included in pywin32 (which isapi-wsgi uses) Are there any other good options that I am missing? It appears you have 4 - how many more exactly are you after? Fair enough - though I don't know if plain CGI is a good option, and IIS FastCGI doesn't seem to work at all. So that leaves classic ASP and the ISAPI stuff. I definitely will be spending some quality time with the ISAPI in the near future. I was concerned about the threading issue because my app (which has several hundred thousand LOC) has always assumed a multiprocess model. But it sounds like if I use the lower level stuff that may not be an issue. I guess the main question I wanted to raise was if anyone has had any success with FastCGI on IIS, or at least might have some idea of what further work might be required to enable it.I will definitely do some experimenting with the pywin32 isapi stuff. And by the way, I just want to thank you personally Mark for all the outstanding work you have done over the years for Python on this platform! Python wouldn't be what it is without you. thanks, -Preston ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
[python-win32] Options for running Python under IIS?
Hello, all! I'm a Python developer trying to get my web app working smoothly under IIS on Windows - in particular with FastCGI though I am open to other options. I posted on the IIS community forums about Python and FastCGI but haven't heard a response there: http://forums.iis.net/p/1162433/1923802.aspx#1923802 The Unix version of my app is based on FastCGI using Flup. (It doesn't use Django or any other public framework, just some hand rolled stuff.) I've got a FastCGI (TCP) based Python service up and running on Windows, thanks to a patched socket module with fromfd() and related patches to Flup that I provide. IIS 7 has a built-in FastCGI plugin but apparently it doesn't work with TCP based servers to my great dismay and seems to be only tested with PHP. It seems to want to manage the launching of backend processes itself. I'd be fine with this if I could tell exactly what interface the IIS FastCGI plugin expects of its executables. PHP has a php-cgi.exe program; has anyone looked at this to see what a Python equivalent might involve? By the way I understand that Python 3 already has the fromfd / dup functionality available. My patch is basically very similar to one posted here: http://bugs.python.org/issue1378 Anyway the purpose of this post is just to see if anyone else is struggling with this issue. As I see it these are my options right now for running Python code under IIS: 1) Plain old CGI - I can get this working but obviously it's not optimal for performance. 2) Classic ASP with Python. This seems OK I guess except classic ASP is deprecated and/or obsolete by this point. There might also be issues with thread safety? My app has never been run or tested in a threaded execution environment. Older versions of my app use Classic ASP Python to talk to backend app servers over a proprietary socket protocol. At least on the Unix side I got rid of this protocol by switching to FastCGI. Under this solution I'd either run my code directly under ASP or else use it as a FastCGI-TCP front end. 3) FastCGI under IIS would be my preferred solution but see above. 4) Use isapi-wsgi: This seems to be getting more popular but it seems to use threads and I'm wondering whether this will break my app in subtle ways. I make heavy use of various Python C extension modules which may not be fully threadsafe. Also within my app code there is extensive use of unprotected module-level Python variables. Or am I misunderstanding how this works? Are there any other good options that I am missing? Even if isapi-wsgi is quite viable (and I plan to start playing with it more this week) it'd still be awesome if we (Python) could work with the IIS FastCGI plugin with something like a python-cgi.exe. thanks, -Preston Landers - planders at gmail dot com ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32