blocking all threads

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alexandru  Mosoi

    blocking all threads

    how can I block all threads for a specific amount of time? (i need to
    sleep whole process for testing purposes). i thought of accessing GIL
    and sleep for some amount of time, but I don't know how to do this and
    whether GIL is recursive.
  • sturlamolden

    #2
    Re: blocking all threads

    On Sep 29, 4:56 pm, Alexandru Mosoi <brtz...@gmail. comwrote:
    how can I block all threads for a specific amount of time? (i need to
    sleep whole process for testing purposes). i thought of accessing GIL
    and sleep for some amount of time, but I don't know how to do this and
    whether GIL is recursive.

    You could do this in C by sleeping while holding the GIL:

    #ifdef WIN32
    #include <Windows.h>
    #define __sleep(ms) Sleep((DWORD)ms )
    #else
    #include <unistd.h>
    #define __sleep(ms) usleep((usecond s_t)ms)
    #endif

    __declspec(dlle xport)
    void sleep(int ms)
    {
    __sleep(ms);
    }


    Save this in a file called "gilsleep.c " and compile it as a DLL
    (gilslepp.dll in Windows, gilsleep.so in Linux). Then in Python:

    import ctypes
    sleep = ctypes.pydll.gi lsleep.sleep
    sleep.argtypes = (ctypes.c_int,)
    sleep.restype = None

    sleep(500) # blocks all threads for 500 ms





















    Comment

    Working...