Re: [python-win32] How to invoke Python program from Windows service?
> Note you can write the service directly in Python using pywin32. If > you want to write the service using some other technology and just > spawn Python, then I'd suggest using just CreateProcess. But with > both CreateProcess and ProcessStartInfo, you need a way to > redirect output from the Python process so you can get diagnostics > from the output - just telling us it is "unsuccessful" doesn't help us > tell you what problem you have. Yeah, that was exactly my problem; I had no way to diagnose what was going on, and needed a springboard to tell me what I needed to know in order to figure out what was happening (or not). I could verify that the script *worked*, since I could run it from a DOS prompt without errors. But when I ran it using CreateProcess (and ProcessStartInfo), I didn't see it execute (since it would have created a file in its directory). However, your answer that I can write it directly with pywin32 intrigues me, especially since I'd rather develop in Python anyway. I'll go see what's involved in doing that. Thanks for the pointer! ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] How to invoke Python program from Windows service?
Matt, > > Yeah, that was exactly my problem; I had no way to diagnose what was going > on, and >needed a springboard to tell me what I needed to know in order to > figure out what was >happening (or not). I could verify that the script > *worked*, since I could run it from a DOS >prompt without errors. But when I > ran it using CreateProcess (and ProcessStartInfo), I >didn't see it execute > (since it would have created a file in its directory). > > However, your answer that I can write it directly with pywin32 intrigues me, > especially since >I'd rather develop in Python anyway. I'll go see what's > involved in doing that. Thanks for the >pointer! From my experiences with Python windows services some things to lookout for: - the "working directory" of the service is usually where the service control programm resides; especially NOT your Python directory - the path is usually the system path. It is not uncommon that Python resides in a different path - network drives are often not mapped for services, so make sure to use UNC-paths - some windows-system-dlls may have the same name as some of your python-programm files (or, even worse, as some of the Python files of any one of standard library or your used libraries). Windows usually looks first into the current directory ... which may have unexpected results when "import " loads .dll from windows, instead of your .py Best wishes, Harald -- LightningTalkMan a brand of GHUM GmbH Spielberger Straße 49 70435 Stuttgart 0173/9409607 ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] How to invoke Python program from Windows service?
> Yeah, that was exactly my problem; I had no way to diagnose what was > going on, and needed a springboard to tell me what I needed to know > in order to figure out what was happening (or not). I could verify > that the script *worked*, since I could run it from a DOS prompt > without errors. But when I ran it using CreateProcess (and > ProcessStartInfo), I didn't see it execute (since it would have > created a file in its directory). > > However, your answer that I can write it directly with pywin32 > intrigues me, especially since I'd rather develop in Python anyway. > I'll go see what's involved in doing that. Thanks for the pointer! For reference, this is the kind of pattern I use when writing Windows Services in Python: class Engine(object): def __init__(self): self._stop_event = threading.Event() def start(self): # do stuff until self._stop_event is set def stop(self): # set self._stop_event if __name__ == '__main__': Engine().start() import win32event import win32service import win32serviceutil import my_module class Service (win32serviceutil.ServiceFramework): _svc_name_ = "MyService" _svc_display_name_ = "A Service of Mine" def __init__ (self, args): win32serviceutil.ServiceFramework.__init__ (self, args) self.stop_event = win32event.CreateEvent (None, 0, 0, None) self.engine = my_module.Engine () def SvcDoRun (self): self.engine.start (True) win32event.WaitForSingleObject (self.stop_event, win32event.INFINITE) def SvcStop (self): self.ReportServiceStatus (win32service.SERVICE_STOP_PENDING) self.engine.stop () win32event.SetEvent (self.stop_event) if __name__ == '__main__': win32serviceutil.HandleCommandLine (Service) To install the service you run the my_service.py module with the parameter "install". (The reverse is done by passing "remove"). HTH TJG ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] How to invoke Python program from Windows service?
Services are pretty tricky - you might be better off arranging for the Python script to write sys.stderr somewhere useful and seeing what the traceback says - you'll almost certainly strike the same problem after you get a pywin32 based one close to working. Mark On 22/06/2012 9:19 PM, Funke, Matt wrote: Note you can write the service directly in Python using pywin32. If you want to write the service using some other technology and just spawn Python, then I'd suggest using just CreateProcess. But with both CreateProcess and ProcessStartInfo, you need a way to redirect output from the Python process so you can get diagnostics from the output - just telling us it is "unsuccessful" doesn't help us tell you what problem you have. Yeah, that was exactly my problem; I had no way to diagnose what was going on, and needed a springboard to tell me what I needed to know in order to figure out what was happening (or not). I could verify that the script *worked*, since I could run it from a DOS prompt without errors. But when I ran it using CreateProcess (and ProcessStartInfo), I didn't see it execute (since it would have created a file in its directory). However, your answer that I can write it directly with pywin32 intrigues me, especially since I'd rather develop in Python anyway. I'll go see what's involved in doing that. Thanks for the pointer! ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] How to invoke Python program from Windows service?
> From my experiences with Python windows services some things to lookout for: > > - the "working directory" of the service is usually where the service control > programm resides; especially NOT your Python directory > > - the path is usually the system path. It is not uncommon that Python resides > in a different path > > - network drives are often not mapped for services, so make sure to use > UNC-paths > > - some windows-system-dlls may have the same name as some of your > python-programm files (or, even worse, as some of the Python files of any > one of standard library or your used libraries). Windows usually looks first > into the current directory ... which may have unexpected results when > "import " loads .dll from windows, instead of your .py Thanks for the heads-up. If I run into some "unexpected results", I'll be sure to try these things first. ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] How to create a empty com object
Hi all , Today I weak up and just came back to my code .. I finally got a good solution for this problem : and here it is ... ..activeComponent=VARIANT(pythoncom.VT_VARIANT | pythoncom.VT_NULL,None) regards, Matteo Il 20/02/2011 23:24, Mark Hammond ha scritto: On 21/02/2011 7:42 AM, Matteo Boscolo wrote: I did some other search I try to pass a object() to the activeComponent but the active component need a COM VARIANT.. there is any way to create a null COM VARIANT ? or to pass a c++ NULL equivalent object ? win32com automatically creates a variant - if you pass None, it will create a variant with VT_NULL, and if you pass pythoncom.Empty, it will pass a variant with VT_EMPTY. If Empty also doesn't work, I'm afraid I'm out of ideas... Cheers, Mark. - Nessun virus nel messaggio. Controllato da AVG - www.avg.com Versione: 10.0.1204 / Database dei virus: 1435/3455 - Data di rilascio: 20/02/2011 ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] How to create a empty com object
Hi all , Today I weak up and just came back to my code .. I finally got a good solution for this problem : and here it is ... ..activeComponent=VARIANT(pythoncom.VT_VARIANT | pythoncom.VT_NULL,None) regards, Matteo Il 20/02/2011 23:24, Mark Hammond ha scritto: On 21/02/2011 7:42 AM, Matteo Boscolo wrote: I did some other search I try to pass a object() to the activeComponent but the active component need a COM VARIANT.. there is any way to create a null COM VARIANT ? or to pass a c++ NULL equivalent object ? win32com automatically creates a variant - if you pass None, it will create a variant with VT_NULL, and if you pass pythoncom.Empty, it will pass a variant with VT_EMPTY. If Empty also doesn't work, I'm afraid I'm out of ideas... Cheers, Mark. - Nessun virus nel messaggio. Controllato da AVG - www.avg.com Versione: 10.0.1204 / Database dei virus: 1435/3455 - Data di rilascio: 20/02/2011 ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] How to invoke Python program from Windows service?
> For reference, this is the kind of pattern I use when writing Windows > Services in Python: This is incredibly useful. Thank you. Matt Funke Programmer/Analyst Vishay Precision Group, Inc. 951 Wendell Blvd Wendell, NC 27591 USA Office: 919-374-5553 Mobile: 919-628-9261 Fax: 919-374-5248 ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] How to invoke Python program from Windows service?
>> For reference, this is the kind of pattern I use when writing Windows >> Services in Python: > This is incredibly useful. Thank you. +1 Malcolm ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Python implementations on Windows 8rt
On Wed, Jun 20, 2012 at 12:37 PM, Tim Roberts wrote: > Chris Lambacher wrote: > > Microsoft has stated that only . NET apps will run on Windows on ARM > > so you will likely need to use IronPython if you want to use Python on > > Windows on Arm. > > That's not correct. The .NET Framework will NOT be ported on Windows > ARM, so .NET applications will not run. Only Metro applications (using > WinRT) will work on Windows ARM. You will not be using Python on > Windows ARM, nor will you be able to distribute Python applications. > Metro apps can be written in so called managed (i.e. .net code) (see: http://blogs.microsoft.co.il/blogs/sasha/archive/2011/09/15/winrt-and-net-in-windows-8.aspx and http://channel9.msdn.com/Events/BUILD/BUILD2011/TOOL-531T ) so theoretically IronPython would be embeddable in an app targeting Metro and could be made to run on Windows RT (the O.S. Formerly know as Windows on ARM). Here is an IronPython mailing list thread on just that: http://mail.python.org/pipermail//ironpython-users/2011-November/015409.html Further investigation also shows that (at least on x86) it might be possible to have a version of Python for Metro Apps that is based on CPython: http://mail.python.org/pipermail/python-dev/2012-January/115426.html > Windows RT (which is what they're calling the version of Windows 8 that > runs on ARM) is to Windows 8 what Android is to Linux. It's a very > restricted, tightly controlled environment. It's Windows for Phones, > not just another port of Windows desktop. > Just to be clear I referred to Windows RT the OS as Windows on ARM to be less confusing with Windows Runtime the programming API for Metro Style Apps. -Chris -- Christopher Lambacher ch...@kateandchris.net ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Getting output parameters from stored procedures
On Wed, Jun 20, 2012 at 10:50 AM, Michael Manfre wrote: > The observed behavior is equivalent to this bit of SQL. > > DECLARE @retval int, @someOut int >> exec @retval = uspReturnsAResultSetOrTwo @someOut OUTPUT >> SELECT @retval, @someOut >> > > I haven't been able to find any documentation stating that this is the > intended behavior and this doesn't match my experience of using stored > procedures with ADO.NET. Is this expected behavior? Is there some > combination of cursor types or attributes to get the output parameter > values without fetching/skipping all the recordsets? > This is the behaviour of the Microsoft's ADO library which is the underlying api that adodbapi works against. It is pretty hard to find docs for ADO because ADO.NET sucks up all the hits and Microsoft's own MSDN docs for ADO are pretty weak. Also, that is fundamentally the pattern you would use with ODBC too which does not have any particular notion of Stored Proceedures. ADO is based on ODBC connections so that may be the source of this particular behind the scenes idiom. -Chris -- Christopher Lambacher ch...@kateandchris.net ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Getting output parameters from stored procedures
I was approaching the conclusion that this is expected behavior. Glad to have it confirmed with a reasonable explanation why. I guess the fix will be to document the behavior. Thanks, Michael Manfre On Fri, Jun 22, 2012 at 11:38 PM, Chris Lambacher wrote: > > > On Wed, Jun 20, 2012 at 10:50 AM, Michael Manfre wrote: > >> The observed behavior is equivalent to this bit of SQL. >> >> DECLARE @retval int, @someOut int >>> exec @retval = uspReturnsAResultSetOrTwo @someOut OUTPUT >>> SELECT @retval, @someOut >>> >> >> I haven't been able to find any documentation stating that this is the >> intended behavior and this doesn't match my experience of using stored >> procedures with ADO.NET. Is this expected behavior? Is there some >> combination of cursor types or attributes to get the output parameter >> values without fetching/skipping all the recordsets? >> > > This is the behaviour of the Microsoft's ADO library which is the > underlying api that adodbapi works against. It is pretty hard to find docs > for ADO because ADO.NET sucks up all the hits and Microsoft's own MSDN > docs for ADO are pretty weak. Also, that is fundamentally the pattern you > would use with ODBC too which does not have any particular notion of Stored > Proceedures. ADO is based on ODBC connections so that may be the source of > this particular behind the scenes idiom. > > -Chris > > -- > Christopher Lambacher > ch...@kateandchris.net > ___ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32