Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 threading example
I'm trying to put together a "threading" example, that has not academic, but practical value.
I thought of people that need to answer questions (or Multiple choices) and have eg. 10 seconds to do so.
The timer is in a separate thread.

So far so good, only I hit a problem: the console input(...) function, while waiting for a user input, seems to
block out any messages coming from the timer thread (style: 'your time is up, next question".)
They only appear after the user has entered something, even after a minute....
Indeed, when I consult the internet for such apps, authors move away from threading to entirely different methods.

Question: can anybody confirm that the console input(...) statement will block out messages coming from a 2nd thread.

PS. There is a solution, i.e. using a GUI. But that makes the example less "pure" with almost a majority
of statements not directly related to "threading".
I would prefer input(...) but maybe that is even more complicated.
If I'm wrong, I'll continue testing... :-)

I think you're not getting any bites because this is not a good application of threading. A common use of threading is to continue working while doing something that blocks. But there is an assumption that the thing that blocks will eventually stop blocking

You could use multi-processing. It is hard to cleanly kill a thread, but multi-processing has "terminate()" for doing just that. Of course using multi-processing does not make a very good threading demo.
OK, thanks,

I gave up on input(...) with a timer running in a separate thread.
I turned to Tkinter, where an entry widget just sits there, waiting for input,
but commands no exclusive attention like input(...). Doing it this way also
has its quirks, but i'm seeing better results. :-)


Top Page

Forum Jump:

Users browsing this thread: 1 Guest(s)