human
4.1.3 派生类"
Please write code following the instructions in jupyter notebook style.

=====
Can you provide a code to 4?
assistant
#Here is code to 4.

import threading
from time import ctime, sleep
class MyThread(threading.Thread):
    def __init__(self, func, args, name =''):
        threading.Thread.__init__(self)
        self.name = name
        self.func = func
        self.args = args
    def getResult(self):
        return self.result
    def run(self):
        print 'starting', self.name, 'at: ', ctime()
        self.result = apply(self.func, self.args)
        print self.name, 'finished at: ', ctime()
def fib(x):
    sleep(0.005)
    if x < 2: return x
    return fib(x-1) + fib(x-2)
def fac(x):
    sleep(0.1)
    if x < 2: return x
    return fac(x-1) * x

def sum(x):
    sleep(0.1)
    if x<2: return x
    return x+sum(x-1)
funcs = [fib, fac, sum]
n = 12 
def main():
    nfuncs = range(len(funcs))
    print '*** SINGLE THREAD'
    for i in nfuncs:
        print 'starting', funcs[i].__name__, 'at: ', ctime()
        print funcs[i](n)
        print funcs[i].__name__, 'finished at: ', ctime()
    print '\n *** MULTI THREAD'
    threads = []
    for i in nfuncs:
        t = MyThread(funcs[i], (n,), funcs[i].__name__)
        threads.append(t)
    for i in nfuncs:
        threads[i].start()
    for i in nfuncs:
        threads[i].join()
        print threads[i].getResult()
    print 'all done'
main()