-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathopenebs_utils.py
66 lines (55 loc) · 1.39 KB
/
openebs_utils.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
#!/usr/bin/env python3
"""
Module for parallel reading writing to file
"""
# import time
import io
from threading import Thread
from requests import get
class Reader(Thread):
"""
Reader class
"""
def __init__(self, file_name):
Thread.__init__(self)
self.file_name = file_name
def run(self):
# print(self.file_name)
with open(self.file_name) as file:
for line in file.readlines():
print("Read " + line)
# time.sleep(1)
class Writer(Thread):
"""
Writer class
"""
def __init__(self, file_name):
Thread.__init__(self)
self.file_name = file_name
def run(self):
# print(self.file_name)
with open(self.file_name, 'w') as file:
for i in range(1, 2000000):
print("Writing ", i)
file.write(str(i))
def run():
"""
Run method
---
You can take different files too.
Reader("file.txt").start()
Writer("another-file.txt").start()
"""
Reader("file.txt").start()
Writer("file.txt").start()
def download(url, file_name):
"""
function to download file over http
url : URL of file to be downloaded
file_name : File name
"""
with io.FileIO(file_name, 'w') as file:
# get request
response = get(url)
# write to file
file.write(response.content)