-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHW14_ Threads_And_Processes_Practice.py
179 lines (171 loc) · 3.66 KB
/
HW14_ Threads_And_Processes_Practice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# Create a script that should find the lines by provided pattern in the provided path directory with recursion (it means
# if the directory has other directories, the script should get all the info from them as well) and threads.
import glob
import time
from concurrent.futures import ThreadPoolExecutor
def find_by_pattern(file, pattern):
line_container = set()
with open(file) as f:
for line in f:
if pattern in line:
line_container.add(line)
return line_container
def find_all_by_pattern(directory_path, pattern):
files = glob.glob(f'{directory_path}/**/*.py', recursive=True)
container = set()
with ThreadPoolExecutor() as pool:
result = pool.map(find_by_pattern, files, pattern*len(files))
for res in result:
container.update(res)
return container
if __name__ == "__main__":
start = time.time()
search_by_pattern = find_all_by_pattern('/home/mariana/Документи/CURSOR', pattern=['import'])
end = time.time() - start
print(f'Search time in {end} seconds')
for line in search_by_pattern:
print(line)
# Output:
# Search time in 0.0265500545501709 seconds
# import pickle
#
# from sys import argv
#
# import HW10_AuthAndReg as Ar
#
# import openpyxl
#
# import dataclasses
#
# import getopt
#
# import random
#
# from ex4 import Open2
#
# import multiprocessing
#
# import json
#
# import time
#
# from threading import current_thread
#
# search_by_patter = find_all_files('.', pattern='import')
#
# import threading
#
# from selenium import webdriver
#
# import functools as f
#
# import datetime
#
# import collections
#
# from select import select
#
# # '03:13': 'and not under the stressful conditions ', '03:15': 'when we usually make these very important decisions. ',
#
# from threading import Thread
#
# import requests
#
# import yaml
#
# from multiprocessing import Process
#
# import xml.etree.ElementTree as ET
#
# # day. ', '00:04': 'But a financial day is just as important. ', '00:07': '[Your Money and Your Mind with Wendy De La
#
# from multiprocessing import Process, Queue
#
# from functools import wraps
#
# import numpy
#
# from time import sleep
#
# import csv
#
# from multiprocessing_examples import Process
#
# from check import *
#
# import asyncio
#
# from abc import ABC, abstractmethod
#
# import pytest
#
# import contextlib
#
# import flask
#
# from multiprocessing import Process, current_process
#
# import os
#
# from __future__ import annotations
#
# from pickle import loads
#
# import socket
#
# import uuid
#
# from flask_restful import Api, Resource, reqparse
#
# from ex1 import Calc
#
# from multiprocessing import Pool, Process
#
# from multiprocessing import Pool
#
# import keyword
#
# from logging import handlers
#
# from ex2 import Vector3f
#
# from functools import reduce
#
# import HW10_RobotCleaner
#
# import sys
#
# from selenium.webdriver.common import keys
#
# from apitest.exceptions import *
#
# search_by_pattern = find_all_by_pattern('/home/mariana/Документи/CURSOR', pattern=['import'])
#
# import argparse
#
# import aiohttp
#
# from apitest.api_script import Register
#
# from requests import HTTPError, ConnectionError
#
# from concurrent.futures import ThreadPoolExecutor
#
# search_by_pattern = find_all_files("C:/Users/YPanin01/PycharmProjects/pythonProject5", pattern='import')
#
# from typing import Dict, Any
#
# # productive as possible. ', '00:52': 'But here are the big headlines that are the most important to cover, ', '00:55':
#
# import glob
#
# from concurrent.futures import ProcessPoolExecutor
#
# from ex1 import __version__ as v
#
# import logging
#
# import unittest
#
#
# Process finished with exit code 0