summaryrefslogtreecommitdiffstats
path: root/scons/fixes.py
blob: 714cccf61d2c5e7773a56eb9b6bf7567c96fa551 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import sys

# Monkey patch os.spawnve on windows to become thread safe
if sys.platform == 'win32':
    import os
    import threading
    from os import spawnve as old_spawnve

    spawn_lock = threading.Lock()

    def new_spawnve(mode, file, args, env):
        spawn_lock.acquire()
        try:
            if mode == os.P_WAIT:
                ret = old_spawnve(os.P_NOWAIT, file, args, env)
            else:
                ret = old_spawnve(mode, file, args, env)
        finally:
            spawn_lock.release()
        if mode == os.P_WAIT:
            pid, status = os.waitpid(ret, 0)
            ret = status >> 8
        return ret

    os.spawnve = new_spawnve