-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsamples.py
More file actions
40 lines (29 loc) · 816 Bytes
/
samples.py
File metadata and controls
40 lines (29 loc) · 816 Bytes
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
from kfifo_queue import Queue
from SharedArray import SharedStructure, SharedField
def task(queue: Queue):
for i in range(10):
data = queue.get()
print("cur get:", data)
def task1(a):
print(a.a)
class Test(SharedStructure):
def __init__(self):
super().__init__("test_")
self.a = SharedField(8)
self.a.value = 12
if __name__ == '__main__':
from multiprocessing import Process
a = Test()
print(a.a)
proc = Process(target=task1, args=(a,))
proc.start()
proc.join()
if __name__ == '__main__':
import multiprocessing as mp
import time
t_que = Queue(buffer_size=1024 * 4)
proc = mp.Process(target=task, args=(t_que,))
proc.start()
for i in range(10):
t_que.put("number: i=%s" % i)
time.sleep(1)