Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
threading example
#1
Hi,
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... :-)

thx,
Paul
Reply
#2
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.
Reply
#3
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. :-)

Paul
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Concurrent futures threading running at same speed as non-threading billykid999 13 1,716 May-03-2023, 08:22 AM
Last Post: billykid999
  Tutorials on sockets, threading and multi-threading? muzikman 2 2,076 Oct-01-2021, 08:32 PM
Last Post: muzikman

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020