[Python-Dev] Subclassing threading.Thread

Bernard Yue bernie@3captus.com
Sun, 09 Jun 2002 02:44:04 -0600


This is a multi-part message in MIME format.
--------------695193BAE1E9F00BD723109A
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Attached files test1.py and test2.py produce different result.  Is it a
bug?


Bernie
--------------695193BAE1E9F00BD723109A
Content-Type: text/plain; charset=us-ascii;
 name="test1.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="test1.py"

#!/usr/bin/env python

import socket
import threading


class server:
    def __init__(self):
        self._addr_local  = ('127.0.0.1', 25339)
        self._s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self._s.bind(self._addr_local)


def test():
    for i in range(10):
        a = threading.Thread( target=server)
        a.start()
        a.run()
        a.join()

if __name__ == '__main__':
    test()


--------------695193BAE1E9F00BD723109A
Content-Type: text/plain; charset=us-ascii;
 name="test2.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="test2.py"

#!/usr/bin/env python

import socket
import threading


class server(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.__addr_local  = ('127.0.0.1', 25339)
        self.__s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.__s.bind(self.__addr_local)

def test():
    for i in range(10):
        a = server()
        a.start()
        a.run()
        a.join()

if __name__ == '__main__':
    test()


--------------695193BAE1E9F00BD723109A--