code: def test_promise_thread_safety():
      """
      Promise tasks should never be executed in a different thread from the one they are scheduled from,
      unless the ThreadPoolExecutor is used.
  
      Here we assert that the pending promise tasks on thread 1 are not executed on thread 2 as thread 2
      resolves its own promise tasks.
      """
      event_1 = threading.Event()
      event_2 = threading.Event()
  
      assert_object = {"is_same_thread": True}
  
      def task_1():
          thread_name = threading.current_thread().getName()
  
          def then_1(value):
              # Enqueue tasks to run later.
              # This relies on the fact that `then` does not execute the function synchronously when called from
              # within another `then` callback function.
              promise = Promise.resolve(None).then(then_2)
              assert promise.is_pending
              event_1.set()  # Unblock main thread
              event_2.wait()  # Wait for thread 2
  
          def then_2(value):
              assert_object["is_same_thread"] = (
                  thread_name == threading.current_thread().getName()
              )
  
          promise = Promise.resolve(None).then(then_1)
  
      def task_2():
          promise = Promise.resolve(None).then(lambda v: None)
          promise.get()  # Drain task queue
          event_2.set()  # Unblock thread 1
  
      thread_1 = threading.Thread(target=task_1)
      thread_1.start()
  
      event_1.wait()  # Wait for Thread 1 to enqueue promise tasks
  
      thread_2 = threading.Thread(target=task_2)
      thread_2.start()
  
      for thread in (thread_1, thread_2):
          thread.join()
  
      assert assert_object["is_same_thread"]
  
imports: from promise import Promise
  from promise.dataloader import DataLoader
  import threading
label_desc: Use image node_id 1 for calling a global function with example usage: test_promise_thread_safety() without return types