#🔒 How to implement threading in the Pythonista app with objc_util?

4 messages · Page 1 of 1 (latest)

fierce glacier
#

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'))
dense pierBOT
#

@fierce glacier

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

dense pierBOT
#

@fierce glacier

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.