Python callback function example
Python callback function example
資料來源: Gemini
code
import threading import time def greet(name): time.sleep(2) # Simulate some processing time print(f"Hello, {name}!") def call_async(name, callback): # Simulate asynchronous execution using a separate thread thread = threading.Thread(target=callback, args=(name,)) thread.start() # Call with a callback function call_async("Alice", greet) print("Other code continues to run...")