-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqueeze.py
More file actions
22 lines (16 loc) · 904 Bytes
/
Copy pathsqueeze.py
File metadata and controls
22 lines (16 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#squeeze.py
import time
from juicer import PyFruitJuicer
#Functions to callback
def print_list(frt_lst):
print("Python; Squeezed everything at once: " + ', '.join(frt_lst) + "!")
def print_string(frt):
print("Python; Squeezed: " + frt)
time.sleep(1)
#Instantiate PyFruitJuicer, C++ FruitJuicer constructor will initiate a thread executing print_list multiple times as a callback.
jcr = PyFruitJuicer(print_list, [b"pear", b"peach", b"mango", b"apple", b"banana", b"pineapple"])#'b' to mark as bytes literals to permit passing to C++
#squeezer() returns the count of fruits handled. print_string will be executed once for each fruit.
print("Total ; " + str(jcr.squeezer(print_string)) + " fruits squeezed!")
#Keep script running until C++ thread has completed work, ensures objects remain in existence.
while False == jcr.checkThreadStatus():
time.sleep(1)