[python-win32] Simple service...

fmml at cedval.org fmml at cedval.org
Sat Sep 4 19:02:31 CEST 2004


Hi all,

Wonderfull, works like a charm, did also tests with Jens's recipe.

Thanks all for the help,

Have a nice week-end,

Francois

> You must check to see if stop signal has been received
> inside your loop.  You should set a timeout (not INFINITE).
>
>
> def SvcDoRun(self):
>     self.timeout=30*60*1000 # Sleep for 30 minutes between runs
>     while 1:
>         #---------------------------------------------------------------------
>         # Wait for service stop signal, if I timeout, loop again
>         #---------------------------------------------------------------------
>         rc=win32event.WaitForSingleObject(self.hWaitStop, self.timeout)
>         #
>         # Check to see if self.hWaitStop happened
>         #
>         if rc == win32event.WAIT_OBJECT_0:
>             #
>             # Stop signal encountered
>             #
>             break
>
>         my_main()
>
>
> and have a SvcStop method:
>
>     def SvcStop(self):
>         #---------------------------------------------------------------------
>         # Before we do anything, tell SCM we are starting the stop
> process.
>         #---------------------------------------------------------------------
>         self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
>         #---------------------------------------------------------------------
>         # And set my event
>         #---------------------------------------------------------------------
>         win32event.SetEvent(self.hWaitStop)
>         return
>
>
> This runs my_main.  When my_main returns, it goes to sleep for 30 minutes
> and
> then it runs again (unless stop signal is received).
>
> HTH,
> Larry Bates
> Syscon, Inc.
>
>
> Message: 5
> Date: Fri, 3 Sep 2004 13:40:24 -0400 (EDT)
> From: fmml at cedval.org
> Subject: [python-win32] Simple service...
> To: python-win32 at python.org
> Message-ID:
> 	<2352.192.168.41.52.1094233224.squirrel at whoami3.cedval.org>
> Content-Type: text/plain;charset=iso-8859-1
>
> Hi all,
>
> I have a script which has a main routine that wakes up every 30 minutes,
> performs a few things and go back to sleep.
>
> I would like to make my script a service. So I wrote a second script that
> imports modules from the first one.
>
> In my code I have the SVCDoRun routine were I run my "my_main()" script
> main loop and it does work, but can't stop the service from the service
> manager.
>
> Goes like this:
>
> def SvcDoRun(self):
>     win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE)
>
>     while 1:
>         my_main()
>
>
> How can I run my script while waiting for the "stop service" signal?
>
>
> Any ideas?
>
>
> Thanks in advance,
>
> Francois
>
>
>
>
>
>
> ------------------------------
>
> Message: 6
> Date: Fri, 03 Sep 2004 19:59:22 +0200
> From: Thomas Heller <theller at python.net>
> Subject: [python-win32] Errors (?) in win32con.py
> To: python-win32 at python.org
> Message-ID: <d613b5dx.fsf at python.net>
> Content-Type: text/plain; charset=us-ascii
>
> I'm currently writing code to parse the windows header files and create
> Python code from them - see recent articles in the ctypes-users mailing
> list.
>
> When I compare the output of my tools with the contents in win32con.py,
> I see several differences.
> One example is the (arbitrarily chosen) CDN_SELCHANGE symbol.
>
> In the commdlg.h file I have I see this:
>
> #define CDN_FIRST (0U - 601U)
> ...
> #define CDN_SELCHANGE (CDN_FIRST - 0x0001)
>
> Ignoring signed/unsigned issues (and not showing the FutureWarning from
> Python 2.3):
>>>> hex(0 - 601 - 1)
> '0xfffffda6'
>>>> import win32con
>>>> hex(win32con.CDN_SELCHANGE)
> '0x4efda6'
>>>>
>
> Looking into the win32con.py source code:
>
> PY_0U = 5177344
> CDN_FIRST = (PY_0U-601)
> CDN_SELCHANGE = (CDN_FIRST - 1)
>
> I'm puzzled.  What is PY_0U?
>
> hex(5177344) is 0x4F0000, but that doesn't enlighten me.
>
> Reading about the CDN_* codes in MSDN, they are used in the NMHDR
> structure's 'code' field, which is UINT.  So the value *is* 32-bit.
>
> Thomas
>
>
>
> ------------------------------
>
> Message: 7
> Date: Fri, 03 Sep 2004 13:08:43 -0500
> From: "Jens B. Jorgensen" <jens.jorgensen at tallan.com>
> Subject: Re: [python-win32] Simple service...
> To: fmml at cedval.org
> Cc: python-win32 at python.org
> Message-ID: <4138B32B.2000803 at tallan.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> fmml at cedval.org wrote:
>
>>Hi all,
>>
>>I have a script which has a main routine that wakes up every 30 minutes,
>>performs a few things and go back to sleep.
>>
>>I would like to make my script a service. So I wrote a second script that
>>imports modules from the first one.
>>
>>In my code I have the SVCDoRun routine were I run my "my_main()" script
>>main loop and it does work, but can't stop the service from the service
>>manager.
>>
>>Goes like this:
>>
>>def SvcDoRun(self):
>>    win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE)
>>
>>    while 1:
>>        my_main()
>>
>>
>>How can I run my script while waiting for the "stop service" signal?
>>
>>
> There are a variety of ways. You could run my_main() in another thread:
>
> def worker_thread() :
>     while 1 :
>        my_main()
>
> def SvcDoRun(self) :
>     thread.start_new_thread(worker_thread, ())
>
>     win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE)
>     sys.exit(0)
>
> but then again if you're just going to do something every 30 minutes and
> it doesn't take long then why not:
>
> def SvcDoRun(self) :
>     thread.start_new_thread(worker_thread, ())
>
>     while 1 :
>         retval = win32event.WaitForSingleObject(self.hWaitStop,
> 30*60*1000)
>        if retval == win32event.WAIT_OBJECT_0 :
>           sys.exit(0)
>        my_main()
>
> and take the waiting 30 minutes bit out of my_main?
>
> Note: I don't see how your above code would run my_main at all since
> you're waiting indefinitely for the stop signal, something wrong there.
>
>>
>>Any ideas?
>>
>>
>>Thanks in advance,
>>
>>Francois
>>
>>
>>
>>
>>_______________________________________________
>>Python-win32 mailing list
>>Python-win32 at python.org
>>http://mail.python.org/mailman/listinfo/python-win32
>>
>>
>
>
> --
> Jens B. Jorgensen
> jens.jorgensen at tallan.com
>
> "With a focused commitment to our clients and our people, we deliver value
> through customized technology solutions"
>
>
>
> ------------------------------
>
> Message: 8
> Date: Fri, 3 Sep 2004 20:51:53 +0200
> From: Marek Kubica <pythonmailing at web.de>
> Subject: [python-win32] COM Browser
> To: Python-win32 mailinglist <python-win32 at python.org>
> Message-ID: <20040903205153.00000320 at galileo>
> Content-Type: text/plain; charset=US-ASCII
>
> Hello!
> Do you know any good standalone COM Browser? I was looking in Google,
> but it only finds the word 'browser' on .com servers (as you can imagene
> there are missions of these pages).
> I just found COM Explorer , but is does not show any Functions of the
> libraries :(
>
> greets,
> Marek
>
>
>
> ------------------------------
>
> Message: 9
> Date: Fri, 3 Sep 2004 14:29:30 -0500
> From: Lewis Franklin <lewis.franklin at gmail.com>
> Subject: Re: [python-win32] Hidden CLI
> To: "Jens B. Jorgensen" <jens.jorgensen at tallan.com>
> Cc: python-win32 at python.org
> Message-ID: <80150ed6040903122918d7dc9c at mail.gmail.com>
> Content-Type: text/plain; charset=US-ASCII
>
> Jens,
>
> I like your idea (I'm modifying code that someone else wrote and they
> apparantly liked curl). However, I was wondering if that works with a
> secure connection. I'm actually accessing https://www.example.com. I
> should have put that earlier, but missed the 's'. The information in
> the module reference was cryptic to me.
>
> My apologies to the win32 thread as well, since most of this
> discussion has in actuality had little to do with Windows API.
>
> Lewis
>
>
> On Fri, 03 Sep 2004 12:08:28 -0500, Jens B. Jorgensen
> <jens.jorgensen at tallan.com> wrote:
>> I have heard it said that it's possible to get a console window to run
>> minimized. I haven't tried it myself but this is probably your best bet.
>> To my knowledge I have not heard of a way to get it not to show up at
>> all.
>>
>> However, noticing that all your doing is running curl instead I'm
>> wondering why you're bothering to run curl at all? Can you not do the
>> same with:
>>
>> import urllib
>>
>> f = open('setup.bat', 'wt')
>> httpf = urllib.urlopen('http://www.example.org?a=user^&b=pass')
>> f.write(httpf.read())
>>
>> That'd be less overh
> ead than spawning an external program anyway!
>>
>>
>>
>> Lewis Franklin wrote:
>>
>> >My question is probably simple to those who have been programming in
>> >Windows for some time, but I am having a difficult time with a
>> >'simple' problem.
>> >
>> >I have written a program that consists simply of three buttons (using
>> >wxPython). Clicking one of those buttons triggers an event where curl
>> >is executed and the information returned is stored into a file. The
>> >command is simply:
>> >
>> >curl http://www.example.org?a=user^&b=pass -o setup.bat
>> >
>> >I can run this command without any problem. However, the 'problem'
>> >that arises is that while curl is being run a Command Prompt appears.
>> >Since this app is for techno-phobes and can only imagine how much
>> >several windows opening and closing on their own would freak them out,
>> >I am trying to keep the user from seeing this window. I was wondering
>> >if there was a way to run the command without having it open a Command
>> >Prompt.
>> >
>> >I hope that I have been clear enough in stating my question and
>> >situation. Thank you in advance for any assistance you can offer.
>> >Being new to Python on Windows I need help with what may seem a small
>> >task to others.
>> >
>> >Lewis
>> >_______________________________________________
>> >Python-win32 mailing list
>> >Python-win32 at python.org
>> >http://mail.python.org/mailman/listinfo/python-win32
>> >
>> >
>>
>> --
>> Jens B. Jorgensen
>> jens.jorgensen at tallan.com
>>
>> "With a focused commitment to our clients and our people, we deliver
>> value
> through customized technology solutions"
>>
>>
>
>
> ------------------------------
>
> _______________________________________________
> Python-win32 mailing list
> Python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
>
>
> End of Python-win32 Digest, Vol 18, Issue 4
>



More information about the Python-win32 mailing list