Live data from Hacker News

Ask HN: Is this a Python bug?

news.ycombinator.com

1–5 of 5 posts

Ask HN: Is this a Python bug?

#1
The run method below never executes in Python 3.5:

from threading import Thread

import time

class MyThread(Thread):

    def __init__(self):

        Thread.__init__(self)

    def run(self):
        while True:
            print("Forever")
            time.sleep(10)

        return

        yield from None
if __name__ == '__main__':

    mt = MyThread()

    mt.start()

    mt.join()

Re: Ask HN: Is this a Python bug?

#3
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

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

Re: Ask HN: Is this a Python bug?

#4

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 2. `return` & `yield from None` are not re…

See https://www.reddit.com/r/Python/comments/4fhels/is_this_a_py...