blocking all threads

Discussion in 'Python' started by Alexandru Mosoi, Sep 29, 2008.

  1. 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.
     
    Alexandru Mosoi, Sep 29, 2008
    #1
    1. Advertising

  2. Alexandru  Mosoi

    sturlamolden Guest

    On Sep 29, 4:56 pm, Alexandru Mosoi <> wrote:

    > 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((useconds_t)ms)
    #endif

    __declspec(dllexport)
    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.gilsleep.sleep
    sleep.argtypes = (ctypes.c_int,)
    sleep.restype = None

    sleep(500) # blocks all threads for 500 ms
     
    sturlamolden, Sep 29, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hendra Gunawan
    Replies:
    1
    Views:
    13,057
    Allan Herriman
    Apr 8, 2004
  2. Andre Kelmanson

    blocking i/o vs. non blocking i/o (performance)

    Andre Kelmanson, Oct 10, 2003, in forum: C Programming
    Replies:
    3
    Views:
    996
    Valentin Tihomirov
    Oct 12, 2003
  3. nukleus
    Replies:
    14
    Views:
    909
    Chris Uppal
    Jan 22, 2007
  4. Replies:
    0
    Views:
    306
  5. Jean-Michel
    Replies:
    0
    Views:
    388
    Jean-Michel
    Dec 22, 2007
Loading...

Share This Page