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

ThreadPoolExecutor storeFile #199

Closed
Zoktog opened this issue Jul 21, 2022 · 1 comment
Closed

ThreadPoolExecutor storeFile #199

Zoktog opened this issue Jul 21, 2022 · 1 comment

Comments

@Zoktog
Copy link

Zoktog commented Jul 21, 2022

Hello, I'm trying to write many files multi-threaded to a directory, but as soon as there are more than 1 threads, copying does not occur. Can this be done somehow?

        with ThreadPoolExecutor(max_workers=os.cpu_count()) as executor:
            results = executor.map(lambda file_path: function(smb_client,
                                                             share_name,
                                                             file_path_local=file_path,
                                                             file_path_remote=file_path_remote), items, timeout=120)

def write_file(self, share_name: str, file_path_local: str, file_path_remote: str, ) -> None:
    with open(file_path_local, 'rb') as file:
                file_name = pathlib.Path(file_path_local).name
                self.conn.storeFile(share_name,  str(pathlib.PurePosixPath(file_path_remote, file_name)), file)
    print(f'file {file_name} was copied')
@miketeo
Copy link
Owner

miketeo commented Jul 21, 2022

My suggestion is to create one pysmb instance for each thread, so each thread will use its own pysmb instance (and underlying SMB connection) to perform your file transfer operation.

@miketeo miketeo closed this as completed Oct 22, 2022
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

2 participants