-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththread-test2.py
68 lines (66 loc) · 2.04 KB
/
thread-test2.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
import subprocess
if __name__ =='__main__':
child = subprocess.Popen(['python','thread-test.py'])
child1 = subprocess.Popen(['python', 'thread-test3.py'])
t =0
while True:
try:
# print("==============I'm parent==========")
import time
# time.sleep(5)
pass
t +=1
# print("##############################################Parent t: ",t)
# import random
# data = {1:'parent',2:[round(random.random(),1) for i in range(3)]}
# child.communicate(data)
except KeyboardInterrupt:
child.kill()
child1.kill()
break
# import os
# import subprocess
# import random
#
#
# def communication(child_writes):
# # file descriptors r, w for reading and writing
# r, w = os.pipe()
#
# # Creating child process using fork
# processid = os.fork()
# if processid:
# # This is the parent process
# # Closes file descriptor w
# # os.close(w)
# r = os.fdopen(r)
# print("Parent reading")
# str = r.read()
# print("Parent reads =", str)
# w = os.fdopen(w)
# import random
#
# data ="Data " #[round(random.random(),2) for i in range(4)]
# w.write(data)
# r.close()
# w.close()
# else:
# # This is the child process
# # os.close(r)
# w = os.fdopen(w, 'w')
# print("Child writing")
# w.write(child_writes)
# print("Child writes = ", child_writes)
# r= os.fdopen(r, 'r')
# data = r.read()
# print("Child get: ",data)
# w.close()
# r.close()
#
# # Driver code
#
#
# child_writes = "Hello geeks"
# communication(child_writes)
#
# # Contributed by "Sharad_Bhardwaj".