wxTimer with no GUI

I’m creating a Windows service using the pywin32 library and need to run the service related tasks at a configurable interval. I have used wx.Timer in the past and like it…However, it looks like it has to be attached to a gui object in order to be created and attach the bindings for handling interval events. Can a wxTimer be used successfully in A NON-GUI application? if so, is there an example of this?


Even if it is possible (I don’t think it is, but would need to dig deeper to say for sure) you wouldn’t want to pull in all the rest of wxPython/wxWidgets into a service process just for the timer. Since you’re using pywin32 I suggest to use the native SetTimer and related API functions. Google can probably find some examples for you.

I agree with Robin. You might also want to take a peek at the Python Standard Library Scheduler module as an alternative.

I found this method to be a decent solution:

import signal
import sys
import time
import random

g_break = False

def continuous_random():
    counter = 0
    while counter<100:
        print('tick: ', random.randint(0, 1000))
        counter += 1
        if g_break:

def sig_handler(sig, frame):
    print("\n\n  Captured CTRL + C...exiting...")
    global g_break
    g_break = True

signal.signal(signal.SIGINT, sig_handler)

python likes ‘try’…signal_1.py (408 Bytes)