This repository has been archived by the owner on Dec 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
87 lines (68 loc) · 1.8 KB
/
example.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
from typing import Any
import multiprocessing_mq as mq
import time
import sys
def init_code():
import os, time
v_int = 123
v_str = "hello world"
v_float = 1.23
v_bool = True
def a(msg):
print(os.getpid())
print(f"The message is: { msg }")
def b():
return "It's from B!"
def c():
for i in range(10):
print(1)
time.sleep(0.5)
def d():
for i in range(10):
print(2)
time.sleep(0.5)
def e(cla):
print(cla.a)
# print(type(cla))
# pass
class my_class():
def __init__(self):
self.a = "from class"
def print_func(self):
print("function from class")
def __call__(self, *args: Any, **kwds: Any) -> Any:
print("Call from class")
def __len__(self):
return 114514
My_class = my_class()
# print(locals())
return locals()
my_pro = mq.Process(init=init_code, suspend=True, rest_time=0.05)
# my_pro.run_without_return("c()")
# my_pro.run_without_return("d()")
# time.sleep(2)
# Two ways to call the function
msg = "hello world"
my_pro.inter.a(msg)
my_pro.run_without_return("a(msg)", args={"msg": msg})
print(my_pro.run_com("b()"))
print(my_pro.inter.b())
# Get some basic type variables
my_pro.inter.v_int = 5
print(my_pro.inter.v_int)
print(my_pro.inter.v_str)
print(my_pro.inter.v_float)
print(my_pro.inter.v_bool)
# Complex class
print(my_pro.inter.My_class.a)
my_pro.inter.My_class.print_func()
my_pro.inter.My_class()
print(my_pro.inter.My_class.__len__())
print(len(my_pro.inter.My_class))
my_pro.inter.new_var = "This is a new var"
print(my_pro.inter.new_var)
my_pro.inter.e(my_pro.inter.My_class)
# time.sleep(1)
# my_pro.stop()
my_pro.forced_stop()
print("finish")