import ctypes
from gi.repository import GLib as glib
#import glib
import signal
import thread
import time

_pthreads_dll = ctypes.CDLL("libpthread.so.0")
_pthread_kill = _pthreads_dll.pthread_kill
def _ignore_handler(signum, frame):
    pass

signal.signal(signal.SIGUSR1, _ignore_handler)

def run_thread():
    time.sleep(10000)

tid = thread.start_new_thread(run_thread, ())

def interrupt():
    # We assume that sizeof(pthread_t) == sizeof(long); this is true for GNU libc anyways
    _pthread_kill(ctypes.c_long(tid), ctypes.c_int(signal.SIGUSR1))

loop1 = glib.MainLoop()
loop2 = glib.MainLoop()
glib.timeout_add(1000, interrupt)
glib.timeout_add(2000, loop1.quit)
loop1.run()


