Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
raw_input blocks a separate thread in Pythonista
-
Hi, running the code below in Pythonista is not working as expected. Looks like the worker thread is being "blocked" by raw_input whereas in other platforms (Raspberry Pi, Windows - both v.2.7.3) same code allows it to run in the background normally.
Can anybody reproduce this and help me understand if this is normal behaviour? Actually this code is just a simplification of what i'm trying to achieve with more complex code. I'm thinking this could probably be a particular iOS limitation.
Thanks for your kind assistance.
import threading import time class Worker(): def PrintSomething(self): while True: print "something" time.sleep(1) if __name__=="__main__": worker=Worker() wthread=threading.Thread(target=worker.PrintSomething) wthread.start() while True: input=raw_input("Your input?: ") #waits for user input and currently blocks 'worker' thread in Pythonista time.sleep(1)
Expected result would be something like:
Your input? : something something something something something something something Your input? : something something ...
But it throws just this:
something Your input?:
-
I posted a similar question before I saw this. I'm having the same problem and can't figure how to work around it. I discovered that you can actually call sys.exit(0) and the thread will keep running in pythonista. the interpreter is showing that it is not running but it still receives print from the running thread.
-
Example of the thread running on exit
<pre><code>
import threading
import time
import sysclass Worker():
def PrintSomething(self):
while True:
print "something"
time.sleep(1)if name=="main":
worker=Worker()
wthread=threading.Thread(target=worker.PrintSomething)
wthread.start()
sys.exit(0)
while True:
#input=raw_input("Your input?: ") #waits for user input and currently blocks 'worker' thread in Pythonista
time.sleep(1)
</code>
</pre>