joaoventura / pybridge

Reuse Python code in native Android applications
215 stars 56 forks source link

Cancelling a python thread or sending a keyboard interrupt signal #15

Closed trbedwards closed 6 years ago

trbedwards commented 6 years ago

Hi there,

Is it possible to retain a reference to a python thread, while it is working, so that you can call stop() on it before it finishes? Or similarly, can you send the 'Ctrl+c' keyboard interrupt to a python thread through the pybridge interface?

The reason I ask is because I am getting SIGSEGV errors when making another network request through pybridge while a network request is ongoing (the network request is being done in python using the requests module).

joaoventura commented 6 years ago

Hello, currently you can only send json formatted strings through the bridge, because it is what is being expected by those functions. The mechanism of pybridge as it currently is, resembles a synchronous call to a function, so until that call ends, you're blocked and cannot do anything more. Even if you use threads on the java side, you are sending json strings to a single python interpreter, so if it is busy you'll have to wait.

Crystax ndk uses python 3.5, maybe you can use something like asyncio for what you need?