Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

操作多线程 #29

Open
hong-xiaobo opened this issue May 21, 2021 · 0 comments
Open

操作多线程 #29

hong-xiaobo opened this issue May 21, 2021 · 0 comments

Comments

@hong-xiaobo
Copy link

hong-xiaobo commented May 21, 2021

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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant