[python-win32] Simple service...

Jens B. Jorgensen jens.jorgensen at tallan.com
Fri Sep 3 20:08:43 CEST 2004


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"  



More information about the Python-win32 mailing list