1. Ronald Oussoren
  2. pyobjc

Commits

Bob Ippolito  committed 097973d

little thing for testing objc.inject

  • Participants
  • Parent commits 8a03848
  • Branches pyobjc-ancient

Comments (0)

Files changed (4)

File sandbox/inject/InjectInterpreterPlugin.py

View file
  • Ignore whitespace
+import os
+global x
+try:
+    x += 1
+except NameError:
+    x = 0
+print x
+print __name__
+print "hi"
+print "INJECTED! pid: %d" % (os.getpid(),)

File sandbox/inject/injectee.py

View file
  • Ignore whitespace
+import os
+print os.getpid()
+from PyObjCTools import AppHelper
+AppHelper.runConsoleEventLoop()

File sandbox/inject/setup.py

View file
  • Ignore whitespace
+from distutils.core import setup
+import py2app
+
+setup(
+    plugin = ["InjectInterpreterPlugin.py"],
+)

File sandbox/inject/test.py

View file
  • Ignore whitespace
+import sys
+import os
+import objc
+if __name__ == '__main__':
+    if len(sys.argv) < 2:
+        raise SystemExit, "%s: You must specify the pid of a process to inject InjectInterpreterPlugin into" % (sys.argv[0],)
+    interp = os.path.abspath('dist/InjectInterpreterPlugin.plugin/Contents/MacOS/InjectInterpreterPlugin')
+    if not os.path.exists(interp):
+        if os.spawnl(os.P_WAIT, sys.executable, sys.executable, 'setup.py', 'py2app', '-A'):
+            raise SystemExit, "Could not build InjectInterpreterPlugin"
+    #objc.inject(int(sys.argv[1]), interp, useMainThread=False)
+    objc.inject(int(sys.argv[1]), interp)