Skip to content

操作多线程 #29

Description

@hong-xiaobo
import time
import os
class Mythread(Thread):
    def __init__(self,path):
        super().__init__()
        self.path=path

    def run(self):
        path=self.path
        files = []
        dirs = []
        for (dirpath, dirnames, filenames) in os.walk(path):
            # files += filenames
            # dirs += dirnames
            # print(files)
            # print(dirs)
            for fn in filenames:
                filepath=os.path.join(dirpath,fn)
                with open(filepath,encoding='utf8')as f:
                    text=f.read()
                    print(text)

filepath=[r'C:\Users\10396\Desktop\新建文件夹',r'C:\Users\10396\Desktop\新建文件夹 (2)']

t=[]
for i in range(2):
    t1=Mythread(filepath[i])
    #print(f'我是主线程{i}')
    t1.start()
    t.append(t1)

for i in t:
    i.join()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions