3 # Jérôme Carretero 2011 (zougloub)
4 # QNX neutrino compatibility functions
7 from waflib
import Utils
11 Popen cannot work on QNX from a threaded program:
12 Forking in threads is not implemented in neutrino.
14 Python's os.popen / spawn / fork won't work when running in threads (they will if in the main program thread)
16 In waf, this happens mostly in build.
17 And the use cases can be replaced by os.system() calls.
19 __slots__
= ["prog", "kw", "popen", "verbose"]
21 def __init__(self
, prog
, **kw
):
27 sys
.stdout
.write("Popen created: %r, kw=%r..." % (prog
, kw
))
29 do_delegate
= kw
.get('stdout') == -1 and kw
.get('stderr') == -1
32 print("Delegating to real Popen")
33 self
.popen
= self
.real_Popen(prog
, **kw
)
37 except Exception as e
:
39 print("Exception: %s" % e
)
42 def __getattr__(self
, name
):
44 sys
.stdout
.write("Getattr: %s..." % name
)
45 if name
in Popen
.__slots
__:
46 return object.__getattribute
__(self
, name
)
48 if self
.popen
is not None:
51 return getattr(self
.popen
, name
)
56 raise Exception("subprocess emulation: not implemented: %s" % name
)
60 print("emulated wait (%r kw=%r)" % (self
.prog
, self
.kw
))
61 if isinstance(self
.prog
, str):
64 cmd
= " ".join(self
.prog
)
66 cmd
= 'cd "%s" && %s' % (self
.kw
['cwd'], cmd
)
69 if sys
.platform
== "qnx6":
70 Popen
.real_Popen
= Utils
.subprocess
.Popen
71 Utils
.subprocess
.Popen
= Popen