Debian Codegraph @

pypy/tool/isolate_slave.py

raw symbols SCIP
1 import sys, os, imp
2 sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..')))
3 from pypy.tool import slaveproc
4
5 class IsolateSlave(slaveproc.Slave):
6 mod = None
7
8 def do_cmd(self, cmd):
9 cmd, data = cmd
10 if cmd == 'load':
11 assert self.mod is None
12 mod = data
13 if isinstance(mod, str):
14 mod = __import__(mod, {}, {}, ['__doc__'])
15 else:
16 dir, name = mod
17 file, pathname, description = imp.find_module(name, [dir])
18 try:
19 mod = imp.load_module(name, file, pathname, description)
20 finally:
21 if file:
22 file.close()
23 self.mod = mod
24 return 'loaded'
25 elif cmd == 'invoke':
26 assert self.mod is not None
27 func, args = data
28 try:
29 res = getattr(self.mod, func)(*args)
30 except KeyboardInterrupt:
31 raise
32 except:
33 exc_type = sys.exc_info()[0]
34 return ('exc', (exc_type.__module__, exc_type.__name__))
35 else:
36 return ('ok', res)
37 else:
38 return 'no-clue'
39
40 if __name__ == '__main__':
41 IsolateSlave().do()