Python callback function example

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...")

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *