blob: 714cccf61d2c5e7773a56eb9b6bf7567c96fa551 [file] [log] [blame]
José Fonseca7325c1e2009-07-14 11:09:23 +01001import sys
2
3# Monkey patch os.spawnve on windows to become thread safe
4if sys.platform == 'win32':
5 import os
6 import threading
7 from os import spawnve as old_spawnve
8
9 spawn_lock = threading.Lock()
10
11 def new_spawnve(mode, file, args, env):
12 spawn_lock.acquire()
13 try:
14 if mode == os.P_WAIT:
15 ret = old_spawnve(os.P_NOWAIT, file, args, env)
16 else:
17 ret = old_spawnve(mode, file, args, env)
18 finally:
19 spawn_lock.release()
20 if mode == os.P_WAIT:
21 pid, status = os.waitpid(ret, 0)
22 ret = status >> 8
23 return ret
24
25 os.spawnve = new_spawnve
26
27