6
6
from tempit import tempit
7
7
8
8
9
+ @tempit
9
10
class TempitTestClass :
10
11
@tempit
11
- def tempit_basic (self ):
12
- time . sleep ( 0.01 )
12
+ def tempit_basic (self , a : int = 1 , b : int = 2 ):
13
+ return a + b
13
14
14
15
@tempit (run_times = 5 )
15
16
def tempit_5times (self ):
@@ -83,26 +84,16 @@ def args_func(a: int = 1, b: int = 2):
83
84
return a + b
84
85
85
86
86
- @tempit (run_times = 5 )
87
- def tempit_other_thread (a : int = 1 , b : int = 2 ):
88
- return a + b
89
-
90
-
91
- @tempit (run_times = 5 )
92
- def tempit_other_process (a : int = 1 , b : int = 2 ):
93
- return a + b
94
-
95
-
96
- @tempit (run_times = 4 , concurrent_execution = True , verbose = True )
87
+ @tempit (run_times = 4 , concurrent_execution = True , verbose = False )
97
88
def call_long_process_concurrent (n ):
98
- for _ in range (2_000_000 ):
89
+ for _ in range (10_000_000 ):
99
90
pass #
100
91
return fib (n )
101
92
102
93
103
- @tempit (run_times = 4 , concurrent_execution = False , verbose = True )
94
+ @tempit (run_times = 4 , concurrent_execution = False , verbose = False )
104
95
def call_long_process_sequential (n ):
105
- for _ in range (2_000_000 ):
96
+ for _ in range (10_000_000 ):
106
97
pass #
107
98
return fib (n )
108
99
@@ -113,27 +104,36 @@ def fib(n):
113
104
return fib (n - 2 ) + fib (n - 1 )
114
105
115
106
116
- @tempit (run_times = 3 , concurrent_execution = True , verbose = False , check_for_recursion = True )
107
+ @tempit (run_times = 1 , concurrent_execution = True , verbose = False )
117
108
def recursive_func (n ):
118
109
if n < 2 :
119
110
return n
120
111
return recursive_func (n - 2 ) + recursive_func (n - 1 )
121
112
122
113
123
- @tempit
124
- def non_recursive_func (n ):
125
- return n
114
+ @tempit (run_times = 1 , concurrent_execution = True , verbose = False )
115
+ def wrapped_recursive_func (n ):
116
+ def recursive_func_wr (n ):
117
+ if n < 2 :
118
+ return n
119
+ return recursive_func_wr (n - 2 ) + recursive_func_wr (n - 1 )
120
+
121
+ return recursive_func (n )
122
+
123
+
124
+ @tempit (run_times = 1 , concurrent_execution = True , verbose = False )
125
+ def tempit_with_recursive_func (n ):
126
+ return recursive_func (n )
126
127
127
128
128
129
@tempit (run_times = 0 , verbose = True )
129
130
def main ():
130
-
131
131
test_class = TempitTestClass ()
132
132
133
133
print ("---CLASS EXAMPLES---" )
134
134
135
135
print ("Once in class basic" )
136
- test_class .tempit_basic ()
136
+ _ = test_class .tempit_basic (1 , b = 2 )
137
137
print ("Concurrency 5 times in class" )
138
138
test_class .tempit_5times ()
139
139
print ("Concurrency 5 times in class verbose" )
@@ -162,19 +162,22 @@ def main():
162
162
future_static_method = executor .submit (test_class .static_method , 1 , b = 2 )
163
163
_ = future_static_method .result ()
164
164
165
- with ProcessPoolExecutor (max_workers = 1 ) as executor :
166
- print ("Other process methods" )
167
- future_basic_method = executor .submit (test_class .tempit_basic )
168
- future_basic_method .result ()
169
- _ , _ = future_class_method .result ()
170
- future_static_method = executor .submit (test_class .static_method , 1 , b = 2 )
171
- _ = future_static_method .result ()
165
+ if False : # This crashes at the moment if the class is decorated with @tempit
166
+ with ProcessPoolExecutor (max_workers = 1 ) as executor :
167
+ print ("Other process methods. This part crashes" )
168
+ future_basic_method = executor .submit (test_class .tempit_basic )
169
+ future_basic_method .result ()
170
+ future_class_method = executor .submit (test_class .class_method , 1 , b = 2 )
171
+ _ , _ = future_class_method .result ()
172
+ future_static_method = executor .submit (test_class .static_method , 1 , b = 2 )
173
+ _ = future_static_method .result ()
172
174
173
175
print ("---END CLASS EXAMPLES---" )
174
176
175
177
print ("---FUNCTION EXAMPLES---" )
176
178
print ("Once basic" )
177
179
tempit_basic ()
180
+
178
181
print ("Concurrency 5 times" )
179
182
tempit_5times ()
180
183
print ("Concurrency 5 times verbose" )
@@ -204,9 +207,11 @@ def main():
204
207
205
208
print ("---END FUNCTION EXAMPLES---" )
206
209
print ("---OTHER EXAMPLES---" )
207
- _ = call_long_process_concurrent (16 )
208
- _ = call_long_process_sequential (16 )
209
210
_ = recursive_func (10 )
211
+ _ = wrapped_recursive_func (10 )
212
+ _ = tempit_with_recursive_func (10 )
213
+ _ = call_long_process_sequential (16 )
214
+ _ = call_long_process_concurrent (16 )
210
215
print ("---END OTHER EXAMPLES---" )
211
216
212
217
0 commit comments