Chris Angelico <ros...@gmail.com> writes: >> > (Side point: The OP's code is quite inefficient, as it creates a new >> > thread for each reiteration, but there's nothing wrong with that if >> > you're looking for something simple.) >> >> It is just something I wrote fast. How could I do this in a better way? > > I'll answer your question, but first and foremost: Your code was fine, > and if something does what it's supposed to, that is the most > important. Everything else is minor.
I like to write efficient code and it never hurts to write better code as just doing what it is supposed to do. ;-) And in my case interval is .5 seconds and when someone is going to use it with an even smaller interval … > But for other ways to do things, I would recommend creating a single > thread function and spawning a single thread to run it, and then > having that function call the target every N seconds. Also, consider Have to be careful that timing keeps correct when target takes a 'lot' of time. Something to ponder about, but can wait. > subclassing Thread rather than subclassing object (which, btw, is the > default; you don't need to say "class X(object)"), which will > automatically give your object all the methods of a timer. Of-course. I should have thought about that. :'-( -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof -- https://mail.python.org/mailman/listinfo/python-list