
Ask HN: Is this a Python bug? - wslh
The run method below never executes in Python 3.5:<p>from threading import Thread<p>import time<p>class MyThread(Thread):<p><pre><code>    def __init__(self):

        Thread.__init__(self)

    def run(self):
        while True:
            print(&quot;Forever&quot;)
            time.sleep(10)

        return

        yield from None
</code></pre>
if __name__ == &#x27;__main__&#x27;:<p><pre><code>    mt = MyThread()

    mt.start()

    mt.join()</code></pre>
======
melor
It is a feature [http://stackoverflow.com/questions/26595895/return-and-
yield...](http://stackoverflow.com/questions/26595895/return-and-yield-in-the-
same-function)

------
ninadmhatre
I dont have access to python 3.5 but i tried above code with some
modifications and it worked!

1\. `while True` has no break condition and that intentional but `mt.join()`
basically waits till all threads are completed? are you looking thread that
keeps on running? i suggest look at daemon thread? if yes, check this
[https://pymotw.com/2/threading/#daemon-vs-non-daemon-
threads](https://pymotw.com/2/threading/#daemon-vs-non-daemon-threads)

2\. `return` & `yield from None` are not required! I had commented those
lines, also 'from' is a reserved keyword

~~~
wslh
See
[https://www.reddit.com/r/Python/comments/4fhels/is_this_a_py...](https://www.reddit.com/r/Python/comments/4fhels/is_this_a_python_bug/)

------
stray
Shouldn't the yield be inside the while loop?

