Dispatching a Win32 COM in the background?

David LeBlanc whisper at oz.net
Fri Jun 21 00:27:57 EDT 2002


Hmmm... actually I don't think either the queue.empty or the sleep are
useful. I believe if you profile this, it's spending all it's time blocked
on the get().

Would this do as well?:

#done gets set by the other thread.
while not done:
	# block here until queue has content
	text = self.text_queue.get()
	speech.Speak(text)

#done became true
#do clean up/exit stuff

David LeBlanc
Seattle, WA USA

> -----Original Message-----
> From: python-list-admin at python.org
> [mailto:python-list-admin at python.org]On Behalf Of Peter Hansen
> Sent: Thursday, June 20, 2002 18:23
> To: python-list at python.org
> Subject: Re: Dispatching a Win32 COM in the background?
>
>
> "Steven M. Castellotti" wrote:
> >
> > Thanks a lot guys, your suggestions have worked perfectly!
> >
> >         Just for the record, here's what the full
> implementation looks like.
>
> Beautiful... thanks for the followup Steven.  I especially like
> your use of deferred imports to speed up initial program loading.
>
> [...]
> >       if not(self.text_queue.empty()):
> >          text = self.text_queue.get()
> >          speech.Speak(text)
> >          time.sleep(.001)
>
> Note that the time.sleep() as shown above is doing nothing
> useful for you.  I suspect you had it unindented but your
> posting probably used tabs and spaces which makes it hard
> to see properly on some readers.
>
> The reason it does nothing useful is that Python will
> automatically switch between different threads every so
> often anyway, so the concept of giving up the CPU for
> what amounts to a tiny fraction of a second is somewhat
> unnecessary.
>
> -Peter
> --
> http://mail.python.org/mailman/listinfo/python-list






More information about the Python-list mailing list