-
Notifications
You must be signed in to change notification settings - Fork 9
Conversation
There's an easy way to restart the runtime without the arduous task of clicking the menu! [Found on StackOverflow](https://stackoverflow.com/a/53165687/336146). ``` import os os.kill(os.getpid(), 9) ``` I also added some comments to explain the benign error messages that appear. I'm not sure where to PR the Colab notebook itself.
Undo unintentional line replacement
That’s a great idea! I tried auto-crashing before the initial Swift-Colab release circa January 2021, but it was generally unreliable. My method called into Python code inside
I would like to prevent this Python code from being automatically exposed to the user’s notebook. One option is to hide it in a special Markdown cell, but that requires clicking two cells. Some people won’t think to click the second cell. I would also have to change several test notebooks. Last but not least, it’s Python code - no way, we use Swift ;) However, adding that as a tip on the README is a perfect idea. I can take it from here, because I have some very strict conventions for style, organization of information, etc. There is a whole Python mode to Swift-Colab, so this could serve a second purpose of auto-restarting the runtime there. Thanks for the contribution! |
when/if the changes are made to the notebook. |
This would be ideal. It involves a process’s PID and the number 9, so it should be related to your Python code. https://stackoverflow.com/questions/2775009/kill-a-process-in-bash#2775021 |
I agree, but this is the special case of relegating Python in favour of Swift! I think 99% of people aren't going to read the first cell, or will appreciate that it is the cell that installs Swift and changes the runtime. The UX benefit is real. |
I'm not sure exactly what you mean here. My two lines are really before Swift-Colab itself kicks in. Where you say "Python mode", I thought all Python from that point on is PythonKit. (bear in mind I'm still just getting familiar with this!)
It's the same.
|
From README.md: Best explanation I have: https://forums.fast.ai/t/python-textfield-output-not-working/51000/14 Work in progress, not yet legible: LanguageModes.md From ColabSupportHistory.md: |
That's true. We could condense the two lines of Python code using a semicolon. But if we can reduce the first cell from |
I'm experimenting with various ways of doing this. I would have to search for the parent to the Bash process. I could kill all Python 3 processes, but that seems excessive and could have unintentional consequences. I have a solution for finding the right parent process, though. However, I need to prevent the flashing cursor ANSI sequence from appearing. Hopefully I will not have to revert to Python. Perhaps I can call Python code from within Bash, given that I know the true parent process's PID. That might avoid the flashing ANSI sequence. |
Python also creates a flashing ANSI sequence, if there was previously output. Maybe I need to send a clear sequence to stdout. This works: !echo "output"
import os
import sys
sys.stdout.flush()
os.kill(os.getpid(), 9) I think I have a solution. Compress the code above onto one line: Problem solved. "The UX benefit is real" and there's no Python code in the notebook. To be more precise, it's physically outside the notebook. Nevermind. There's an indentation error in the Python interpreter. I'll figure out what to do tomorrow. If there's no solution that satisfies my two requirements above, it will just be strongly recommended advice in the README. |
There's an easy way to restart the runtime without the arduous task of clicking the menu! Found on StackOverflow.
I also added some comments to explain the benign error messages that appear.
I'm not sure where to PR the Colab notebook itself.