-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpen-Two-Process.py
More file actions
83 lines (65 loc) · 2.58 KB
/
Open-Two-Process.py
File metadata and controls
83 lines (65 loc) · 2.58 KB
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
def start_mongod():
process1 = subprocess.Popen(
['mongod' , '--port' , '27019' , '--dbpath' , 'c:\data\db'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
time.sleep(3)
process2 = subprocess.Popen(
['mongo' , '--port' ,'27019'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
process2.stdin.write('use admin;\n'.encode())
# process1.stdin.close() # Close stdin to signal end of input
for line in process1.stdout:
print(line.decode().strip())
for line in process1.stderr:
print(line.decode().strip())
for line in process2.stdout:
print(line.decode().strip())
for line in process2.stderr:
print(line.decode().strip())
# Wait for the process to finish
process1.wait()
process2.wait()
print("mongod process exited with return code:", process1.returncode)
# 1- start process async on main thread
# start_mongod()
# 2- start process on new thread
# Start the mongod process in a new thread
# mongod_thread = threading.Thread(target=start_mongod)
# mongod_thread.start()
3- start process on new thread
with ThreadPoolExecutor(max_workers=1) as executor:
future = executor.submit(start_mongod)
print("=====================================")
print("=====================================")
print("=====================================")
print("=====================================")
print("=====================================")
print("=====================================")
print("=====================================")
print("=====================================")
print("=====================================")
print("=====================================")
print("=====================================")
print("=====================================")
print("=====================================")
print("=====================================")
print("=====================================")
print("=====================================")
print("=====================================")
print("=====================================")
print("=====================================")
print("=====================================")
print("=====================================")
print("=====================================")
print("=====================================")
print("=====================================")
print("=====================================")
print("=====================================")
print("=====================================")
print("=====================================")