Does anyone here have any experience with the objc_util library from the Pythonista iOS app? I’ve been trying to work on a little project but I’ve gotten stuck on some details.
My eventual goal is to interface with the device’s Python binary (I am jailbroken), as the Python interpreter included with Pythonista is limited to pure Python packages (along with ctypes and the aforementioned objc_util, which allows the programmer to interface with the underlying objective C.
I’ve gotten to the point where I’ve successfully spawned a system Python binary, but I am struggling to get the NSTask to be terminated when the python program is terminated. The app just hangs and the KeyboardInterrupt button does nothing. Does anyone know of a fix for this? Does it involve threading? This is my code so far:
from objc_util import *
import pykit_io
NSTask = ObjCClass('NSTask')
python = NSTask.alloc().init()
python.setLaunchPath_('/var/jb/usr/bin/python3.9')
args = NSMutableArray.alloc().init()
args.addObject_(ns('-uI'))
python.setArguments_(args)
stdout_pipe = ObjCClass('NSPipe').pipe()
python.setStandardOutput_(stdout_pipe)
stderr_pipe = ObjCClass('NSPipe').pipe()
python.setStandardError_(stderr_pipe)
stdin_pipe = ObjCClass('NSPipe').pipe()
python.setStandardInput_(stdin_pipe)
stdout_handle = stdout_pipe.fileHandleForReading()
stderr_handle = stderr_pipe.fileHandleForReading()
stdin_handle = stdin_pipe.fileHandleForWriting()
python.launch()
python.waitUntilExit()
python.release()
stdout_data = stdout_handle.readDataToEndOfFile()
pykit_io.write_stdout(str(nsdata_to_bytes(stdout_data), encoding='utf8'))
stderr_data = stderr_handle.readDataToEndOfFile()
pykit_io.write_stderr(str(nsdata_to_bytes(stderr_data), encoding='utf8'))