kivy / kivy/python-for-android
Improve process for stopping python
- Langage dominant
- Python
- Étoiles
- 8.9k
- Forks
- 2k
- Merge moyen
- 12 h 20 min
- PR mergées (30 j)
- 9
Description
### Checklist
- [x] the issue is indeed a bug and not a support request
- [x] issue doesn't already exist: https://github.com/kivy/python-for-android/issues
- [ ] I have a short, runnable example that reproduces the issue
- [x] I reproduced the problem with the latest development version (`p4a.branch = develop`)
- [x] I used the grave accent (aka backticks) to format code or logs when appropriated
### Versions
- Python: 3.9
- OS: Linux
- Kivy: N/A
- Cython: N/A
- OpenJDK: 11
### Description
Right now the way the `Activity` and `Service` classes stop python is to kill the whole process. That's a very heavy handed way to stop the python thread since it prevents the application taking any action when it has to stop.
I think an one way to do this would be to define a custom python exception and raise it in the python interpreter. The application could catch the exception, perform any actions it needs, and then return gracefully. From the Java side, it would run this via the JNI from a different thread than python is running in. In that case, I believe you could use one of [these](https://docs.python.org/3/c-api/init.html#asynchronous-notifications) [two](https://docs.python.org/3/c-api/init.html#gilstate) mechanisms to [raise the exception](https://docs.python.org/3/c-api/exceptions.html#raising-exceptions) in the python main thread.
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Commencez par localiser les classes Activity et Service qui arrêtent actuellement Python en tuant le processus, puis consultez la documentation liée de la Python C API sur les notifications asynchrones, l’état du GIL et le déclenchement d’exceptions. Déterminez comment des appels JNI côté Java pourraient demander un arrêt propre depuis un autre thread, et définissez l’achèvement comme le fait de permettre à l’application d’intercepter la condition d’arrêt et d’effectuer le nettoyage avant de retourner.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- android, java, python
- Domaine
- mobile
- Type d'issue
- Bug
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 25/100