Threading

Is there something off with Python threads in Blender? Some of the print statements in threads don’t seem to work, while others do. For example, in the code below, the first print in setter() doesn’t show anything but the following ones do print.

import os
import threading
import time
from ctypes import *

def setter():
    h0 = windll.kernel32.CreateEventA(None, 0, 0, "Local\\core_alive")
    print(threading.current_thread().name, "Starting")
    time.sleep(3)
    print("setting event")
    windll.kernel32.SetEvent(h0)
    windll.kernel32.CloseHandle(h0)
    print("exiting")

def waiter():
    h1 = windll.kernel32.OpenEventA(0x0002 | 0x00100000, 0, "Local\\core_alive")
    print("waiting", h1)
    ret = windll.kernel32.WaitForSingleObject(h1, 5000)
    if ret == 0x0:
        print("set")
    elif ret == 0x102:
        print("timeout")
    elif ret == 0xFFFFFFFF:
        print("failed")
    else:
        print("unknown")
    windll.kernel32.CloseHandle(h1)

setterThread = threading.Thread(name="setter", target=setter)
setterThread.start()

waiter()

You could try to add the brackets in:

setterThread = threading.Thread( target=setter())

http://www.blender.org/documentation/blender_python_api_2_66_4/info_gotcha.html#strange-errors-using-threading-module