What does `exit` keyword do in Python3 with Jupyter Notebook?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
9
down vote

favorite












I am currently using Python3 in Jupyter Notebook and I just ran into a keyword exit. What does this keyword do ?



with open("some_file.txt") as f:
for lines in f:
print(lines)
exit









share|improve this question

















  • 2




    Undoing my dupe-close because apparently this behaves differently in Jupyter/IPython.
    – user2357112
    Dec 7 at 19:57










  • Is that exit something specific to jupyter? Normally in python the code uses sys.exit(). Whatever this does it will do it for every line read from the file.
    – Kingsley
    Dec 7 at 20:02











  • exit is not a key-word.
    – juanpa.arrivillaga
    Dec 7 at 20:08














up vote
9
down vote

favorite












I am currently using Python3 in Jupyter Notebook and I just ran into a keyword exit. What does this keyword do ?



with open("some_file.txt") as f:
for lines in f:
print(lines)
exit









share|improve this question

















  • 2




    Undoing my dupe-close because apparently this behaves differently in Jupyter/IPython.
    – user2357112
    Dec 7 at 19:57










  • Is that exit something specific to jupyter? Normally in python the code uses sys.exit(). Whatever this does it will do it for every line read from the file.
    – Kingsley
    Dec 7 at 20:02











  • exit is not a key-word.
    – juanpa.arrivillaga
    Dec 7 at 20:08












up vote
9
down vote

favorite









up vote
9
down vote

favorite











I am currently using Python3 in Jupyter Notebook and I just ran into a keyword exit. What does this keyword do ?



with open("some_file.txt") as f:
for lines in f:
print(lines)
exit









share|improve this question













I am currently using Python3 in Jupyter Notebook and I just ran into a keyword exit. What does this keyword do ?



with open("some_file.txt") as f:
for lines in f:
print(lines)
exit






python jupyter-notebook exit keyword






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 7 at 19:53









Poream3387

518214




518214







  • 2




    Undoing my dupe-close because apparently this behaves differently in Jupyter/IPython.
    – user2357112
    Dec 7 at 19:57










  • Is that exit something specific to jupyter? Normally in python the code uses sys.exit(). Whatever this does it will do it for every line read from the file.
    – Kingsley
    Dec 7 at 20:02











  • exit is not a key-word.
    – juanpa.arrivillaga
    Dec 7 at 20:08












  • 2




    Undoing my dupe-close because apparently this behaves differently in Jupyter/IPython.
    – user2357112
    Dec 7 at 19:57










  • Is that exit something specific to jupyter? Normally in python the code uses sys.exit(). Whatever this does it will do it for every line read from the file.
    – Kingsley
    Dec 7 at 20:02











  • exit is not a key-word.
    – juanpa.arrivillaga
    Dec 7 at 20:08







2




2




Undoing my dupe-close because apparently this behaves differently in Jupyter/IPython.
– user2357112
Dec 7 at 19:57




Undoing my dupe-close because apparently this behaves differently in Jupyter/IPython.
– user2357112
Dec 7 at 19:57












Is that exit something specific to jupyter? Normally in python the code uses sys.exit(). Whatever this does it will do it for every line read from the file.
– Kingsley
Dec 7 at 20:02





Is that exit something specific to jupyter? Normally in python the code uses sys.exit(). Whatever this does it will do it for every line read from the file.
– Kingsley
Dec 7 at 20:02













exit is not a key-word.
– juanpa.arrivillaga
Dec 7 at 20:08




exit is not a key-word.
– juanpa.arrivillaga
Dec 7 at 20:08












3 Answers
3






active

oldest

votes

















up vote
7
down vote



accepted










The exit lines in your loop do nothing. Why they do nothing is a bit more complicated than the usual reason exit would do nothing in Python, though.




Normally, exit on a line by its own wouldn't exit Python. At most, in interactive mode, it would print a message telling you how to quit Python (message implemented in _sitebuiltins.Quitter.__repr__):



>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit


IPython does something different. Among the many extra systems IPython has for interactive convenience is a system to autocall instances of a certain type, IPython.core.autocall.IPyAutocall. (This is similar to but distinct from the %autocall magic.)



In IPython, exit and quit are set to instances of IPython.core.autocall.ExitAutocall, a subclass of IPyAutocall. IPython recognizes objects of this type, so when a line containing just exit or quit is executed, IPython actually exits.



In [1]: exit
[IPython dies here]


A Jupyter notebook's IPython kernel has exit and quit set to instances of the very closely related IPython.core.autocall.ZMQExitAutocall, which has some extra functionality to support a keep_kernel argument, but is otherwise the same.



This functionality only triggers when a line referring to the autocallable object is the entire content of the cell, though. Inside a loop, the autocall functionality doesn't trigger, so we're back to nothing happening.



In fact, even less happens than what would happen in normal interactive mode - in a normal, non-IPython interactive session, this loop would print the "Use exit()..." message on each iteration, due to differences in how IPython and the regular interactive mode handle expression auto-printing.






share|improve this answer






















  • It also has an optional parameter to keep the kernel running - github.com/jupyter/jupyter_console/issues/…
    – Kingsley
    Dec 7 at 20:08










  • @Kingsley which I assume Spyder is doing in my case, and I suspect Jupyter would invoke by default. I can't see much use for this other than a wipe of the namespace otherwise. If you actually shut the IPython kernel down then you can't do a whole lot
    – roganjosh
    Dec 7 at 20:09










  • Actually, it might be a part of IPython.core.autocall.ZMQExitAutocall The behaviour and the parameter seems to support it.
    – Paritosh Singh
    Dec 7 at 20:20

















up vote
4
down vote













When exit (sic, with no parentheses) is used in iPython in a loop or a branch of a conditional statement, it is doing nothing because it is simply a reference to an instance of IPython.core.autocall.ExitAutocall:



for i in range(10): 
exit
print(i)
# 9

if i==9:
exit
print(exit)
# <IPython.core.autocall.ExitAutocall object at 0x7f76ad78a4a8>


It does not restart the kernel:



print(i)
# 9


However, when used on the command line alone, it is treated as a kind of magic (though without a %) and terminates the kernel.






share|improve this answer






















  • No, it really isn't sic. It does do something in IPython
    – roganjosh
    Dec 7 at 20:15










  • I can run it in the IPython console and it forces a reset in Spyder
    – roganjosh
    Dec 7 at 20:16










  • No, it looks like this is right - the loop changes things in a way I didn't account for. I need to revise my answer a bit more.
    – user2357112
    Dec 7 at 20:16










  • @roganjosh Like it is doing what?
    – DYZ
    Dec 7 at 20:17






  • 1




    @roganjosh Pretty much so. Just like any other reference to an object or a function.
    – DYZ
    Dec 7 at 20:22

















up vote
3
down vote













On my simple test,

Cell 1
a = 3

Cell 2
exit

cell 3
print(a)



resulted in



---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-3f786850e387> in <module>
----> 1 a

NameError: name 'a' is not defined


exit just kills the kernel that the notebook is relying on for execution.



Interestingly enough however, There seems to be a parameter you can pass to modify that behaviour as well.



Test 2:
Cell 1
a = 3

Cell 2
exit(keep_kernel=True)

cell 3
print(a)
resulted in
3



EDIT: And looks like @user2357112's answer fills in the missing pieces.

EDIT2: Actually, it seems to be an instance of IPython.core.autocall.ZMQExitAutocall



 class IPython.core.autocall.ZMQExitAutocall(ip=None)

Bases: IPython.core.autocall.ExitAutocall

Exit IPython. Autocallable, so it needn’t be explicitly called.
Parameters: keep_kernel (bool) – If True, leave the kernel alive. Otherwise, tell the kernel to exit too (default).





share|improve this answer






















  • Ah nice. I was trying to work out what this might do. So it looks like, from your test, it wipes the namespace?
    – roganjosh
    Dec 7 at 20:03






  • 1




    In Spyder it is restarting the IPython kernel. You already have my upvote, but I think you could do with adding the documentation for this (my lame way of backing out of a fiddly google search :P)
    – roganjosh
    Dec 7 at 20:05






  • 2




    mhm, i am actually really intrigued by this behaviour, tracking down the documentation atm, however check the edit. @roganjosh It makes me suspect it is doing something not just with namespaces.
    – Paritosh Singh
    Dec 7 at 20:07










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53676034%2fwhat-does-exit-keyword-do-in-python3-with-jupyter-notebook%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
7
down vote



accepted










The exit lines in your loop do nothing. Why they do nothing is a bit more complicated than the usual reason exit would do nothing in Python, though.




Normally, exit on a line by its own wouldn't exit Python. At most, in interactive mode, it would print a message telling you how to quit Python (message implemented in _sitebuiltins.Quitter.__repr__):



>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit


IPython does something different. Among the many extra systems IPython has for interactive convenience is a system to autocall instances of a certain type, IPython.core.autocall.IPyAutocall. (This is similar to but distinct from the %autocall magic.)



In IPython, exit and quit are set to instances of IPython.core.autocall.ExitAutocall, a subclass of IPyAutocall. IPython recognizes objects of this type, so when a line containing just exit or quit is executed, IPython actually exits.



In [1]: exit
[IPython dies here]


A Jupyter notebook's IPython kernel has exit and quit set to instances of the very closely related IPython.core.autocall.ZMQExitAutocall, which has some extra functionality to support a keep_kernel argument, but is otherwise the same.



This functionality only triggers when a line referring to the autocallable object is the entire content of the cell, though. Inside a loop, the autocall functionality doesn't trigger, so we're back to nothing happening.



In fact, even less happens than what would happen in normal interactive mode - in a normal, non-IPython interactive session, this loop would print the "Use exit()..." message on each iteration, due to differences in how IPython and the regular interactive mode handle expression auto-printing.






share|improve this answer






















  • It also has an optional parameter to keep the kernel running - github.com/jupyter/jupyter_console/issues/…
    – Kingsley
    Dec 7 at 20:08










  • @Kingsley which I assume Spyder is doing in my case, and I suspect Jupyter would invoke by default. I can't see much use for this other than a wipe of the namespace otherwise. If you actually shut the IPython kernel down then you can't do a whole lot
    – roganjosh
    Dec 7 at 20:09










  • Actually, it might be a part of IPython.core.autocall.ZMQExitAutocall The behaviour and the parameter seems to support it.
    – Paritosh Singh
    Dec 7 at 20:20














up vote
7
down vote



accepted










The exit lines in your loop do nothing. Why they do nothing is a bit more complicated than the usual reason exit would do nothing in Python, though.




Normally, exit on a line by its own wouldn't exit Python. At most, in interactive mode, it would print a message telling you how to quit Python (message implemented in _sitebuiltins.Quitter.__repr__):



>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit


IPython does something different. Among the many extra systems IPython has for interactive convenience is a system to autocall instances of a certain type, IPython.core.autocall.IPyAutocall. (This is similar to but distinct from the %autocall magic.)



In IPython, exit and quit are set to instances of IPython.core.autocall.ExitAutocall, a subclass of IPyAutocall. IPython recognizes objects of this type, so when a line containing just exit or quit is executed, IPython actually exits.



In [1]: exit
[IPython dies here]


A Jupyter notebook's IPython kernel has exit and quit set to instances of the very closely related IPython.core.autocall.ZMQExitAutocall, which has some extra functionality to support a keep_kernel argument, but is otherwise the same.



This functionality only triggers when a line referring to the autocallable object is the entire content of the cell, though. Inside a loop, the autocall functionality doesn't trigger, so we're back to nothing happening.



In fact, even less happens than what would happen in normal interactive mode - in a normal, non-IPython interactive session, this loop would print the "Use exit()..." message on each iteration, due to differences in how IPython and the regular interactive mode handle expression auto-printing.






share|improve this answer






















  • It also has an optional parameter to keep the kernel running - github.com/jupyter/jupyter_console/issues/…
    – Kingsley
    Dec 7 at 20:08










  • @Kingsley which I assume Spyder is doing in my case, and I suspect Jupyter would invoke by default. I can't see much use for this other than a wipe of the namespace otherwise. If you actually shut the IPython kernel down then you can't do a whole lot
    – roganjosh
    Dec 7 at 20:09










  • Actually, it might be a part of IPython.core.autocall.ZMQExitAutocall The behaviour and the parameter seems to support it.
    – Paritosh Singh
    Dec 7 at 20:20












up vote
7
down vote



accepted







up vote
7
down vote



accepted






The exit lines in your loop do nothing. Why they do nothing is a bit more complicated than the usual reason exit would do nothing in Python, though.




Normally, exit on a line by its own wouldn't exit Python. At most, in interactive mode, it would print a message telling you how to quit Python (message implemented in _sitebuiltins.Quitter.__repr__):



>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit


IPython does something different. Among the many extra systems IPython has for interactive convenience is a system to autocall instances of a certain type, IPython.core.autocall.IPyAutocall. (This is similar to but distinct from the %autocall magic.)



In IPython, exit and quit are set to instances of IPython.core.autocall.ExitAutocall, a subclass of IPyAutocall. IPython recognizes objects of this type, so when a line containing just exit or quit is executed, IPython actually exits.



In [1]: exit
[IPython dies here]


A Jupyter notebook's IPython kernel has exit and quit set to instances of the very closely related IPython.core.autocall.ZMQExitAutocall, which has some extra functionality to support a keep_kernel argument, but is otherwise the same.



This functionality only triggers when a line referring to the autocallable object is the entire content of the cell, though. Inside a loop, the autocall functionality doesn't trigger, so we're back to nothing happening.



In fact, even less happens than what would happen in normal interactive mode - in a normal, non-IPython interactive session, this loop would print the "Use exit()..." message on each iteration, due to differences in how IPython and the regular interactive mode handle expression auto-printing.






share|improve this answer














The exit lines in your loop do nothing. Why they do nothing is a bit more complicated than the usual reason exit would do nothing in Python, though.




Normally, exit on a line by its own wouldn't exit Python. At most, in interactive mode, it would print a message telling you how to quit Python (message implemented in _sitebuiltins.Quitter.__repr__):



>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit


IPython does something different. Among the many extra systems IPython has for interactive convenience is a system to autocall instances of a certain type, IPython.core.autocall.IPyAutocall. (This is similar to but distinct from the %autocall magic.)



In IPython, exit and quit are set to instances of IPython.core.autocall.ExitAutocall, a subclass of IPyAutocall. IPython recognizes objects of this type, so when a line containing just exit or quit is executed, IPython actually exits.



In [1]: exit
[IPython dies here]


A Jupyter notebook's IPython kernel has exit and quit set to instances of the very closely related IPython.core.autocall.ZMQExitAutocall, which has some extra functionality to support a keep_kernel argument, but is otherwise the same.



This functionality only triggers when a line referring to the autocallable object is the entire content of the cell, though. Inside a loop, the autocall functionality doesn't trigger, so we're back to nothing happening.



In fact, even less happens than what would happen in normal interactive mode - in a normal, non-IPython interactive session, this loop would print the "Use exit()..." message on each iteration, due to differences in how IPython and the regular interactive mode handle expression auto-printing.







share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 7 at 20:35

























answered Dec 7 at 20:06









user2357112

149k12156244




149k12156244











  • It also has an optional parameter to keep the kernel running - github.com/jupyter/jupyter_console/issues/…
    – Kingsley
    Dec 7 at 20:08










  • @Kingsley which I assume Spyder is doing in my case, and I suspect Jupyter would invoke by default. I can't see much use for this other than a wipe of the namespace otherwise. If you actually shut the IPython kernel down then you can't do a whole lot
    – roganjosh
    Dec 7 at 20:09










  • Actually, it might be a part of IPython.core.autocall.ZMQExitAutocall The behaviour and the parameter seems to support it.
    – Paritosh Singh
    Dec 7 at 20:20
















  • It also has an optional parameter to keep the kernel running - github.com/jupyter/jupyter_console/issues/…
    – Kingsley
    Dec 7 at 20:08










  • @Kingsley which I assume Spyder is doing in my case, and I suspect Jupyter would invoke by default. I can't see much use for this other than a wipe of the namespace otherwise. If you actually shut the IPython kernel down then you can't do a whole lot
    – roganjosh
    Dec 7 at 20:09










  • Actually, it might be a part of IPython.core.autocall.ZMQExitAutocall The behaviour and the parameter seems to support it.
    – Paritosh Singh
    Dec 7 at 20:20















It also has an optional parameter to keep the kernel running - github.com/jupyter/jupyter_console/issues/…
– Kingsley
Dec 7 at 20:08




It also has an optional parameter to keep the kernel running - github.com/jupyter/jupyter_console/issues/…
– Kingsley
Dec 7 at 20:08












@Kingsley which I assume Spyder is doing in my case, and I suspect Jupyter would invoke by default. I can't see much use for this other than a wipe of the namespace otherwise. If you actually shut the IPython kernel down then you can't do a whole lot
– roganjosh
Dec 7 at 20:09




@Kingsley which I assume Spyder is doing in my case, and I suspect Jupyter would invoke by default. I can't see much use for this other than a wipe of the namespace otherwise. If you actually shut the IPython kernel down then you can't do a whole lot
– roganjosh
Dec 7 at 20:09












Actually, it might be a part of IPython.core.autocall.ZMQExitAutocall The behaviour and the parameter seems to support it.
– Paritosh Singh
Dec 7 at 20:20




Actually, it might be a part of IPython.core.autocall.ZMQExitAutocall The behaviour and the parameter seems to support it.
– Paritosh Singh
Dec 7 at 20:20












up vote
4
down vote













When exit (sic, with no parentheses) is used in iPython in a loop or a branch of a conditional statement, it is doing nothing because it is simply a reference to an instance of IPython.core.autocall.ExitAutocall:



for i in range(10): 
exit
print(i)
# 9

if i==9:
exit
print(exit)
# <IPython.core.autocall.ExitAutocall object at 0x7f76ad78a4a8>


It does not restart the kernel:



print(i)
# 9


However, when used on the command line alone, it is treated as a kind of magic (though without a %) and terminates the kernel.






share|improve this answer






















  • No, it really isn't sic. It does do something in IPython
    – roganjosh
    Dec 7 at 20:15










  • I can run it in the IPython console and it forces a reset in Spyder
    – roganjosh
    Dec 7 at 20:16










  • No, it looks like this is right - the loop changes things in a way I didn't account for. I need to revise my answer a bit more.
    – user2357112
    Dec 7 at 20:16










  • @roganjosh Like it is doing what?
    – DYZ
    Dec 7 at 20:17






  • 1




    @roganjosh Pretty much so. Just like any other reference to an object or a function.
    – DYZ
    Dec 7 at 20:22














up vote
4
down vote













When exit (sic, with no parentheses) is used in iPython in a loop or a branch of a conditional statement, it is doing nothing because it is simply a reference to an instance of IPython.core.autocall.ExitAutocall:



for i in range(10): 
exit
print(i)
# 9

if i==9:
exit
print(exit)
# <IPython.core.autocall.ExitAutocall object at 0x7f76ad78a4a8>


It does not restart the kernel:



print(i)
# 9


However, when used on the command line alone, it is treated as a kind of magic (though without a %) and terminates the kernel.






share|improve this answer






















  • No, it really isn't sic. It does do something in IPython
    – roganjosh
    Dec 7 at 20:15










  • I can run it in the IPython console and it forces a reset in Spyder
    – roganjosh
    Dec 7 at 20:16










  • No, it looks like this is right - the loop changes things in a way I didn't account for. I need to revise my answer a bit more.
    – user2357112
    Dec 7 at 20:16










  • @roganjosh Like it is doing what?
    – DYZ
    Dec 7 at 20:17






  • 1




    @roganjosh Pretty much so. Just like any other reference to an object or a function.
    – DYZ
    Dec 7 at 20:22












up vote
4
down vote










up vote
4
down vote









When exit (sic, with no parentheses) is used in iPython in a loop or a branch of a conditional statement, it is doing nothing because it is simply a reference to an instance of IPython.core.autocall.ExitAutocall:



for i in range(10): 
exit
print(i)
# 9

if i==9:
exit
print(exit)
# <IPython.core.autocall.ExitAutocall object at 0x7f76ad78a4a8>


It does not restart the kernel:



print(i)
# 9


However, when used on the command line alone, it is treated as a kind of magic (though without a %) and terminates the kernel.






share|improve this answer














When exit (sic, with no parentheses) is used in iPython in a loop or a branch of a conditional statement, it is doing nothing because it is simply a reference to an instance of IPython.core.autocall.ExitAutocall:



for i in range(10): 
exit
print(i)
# 9

if i==9:
exit
print(exit)
# <IPython.core.autocall.ExitAutocall object at 0x7f76ad78a4a8>


It does not restart the kernel:



print(i)
# 9


However, when used on the command line alone, it is treated as a kind of magic (though without a %) and terminates the kernel.







share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 7 at 20:49

























answered Dec 7 at 20:14









DYZ

25.1k61948




25.1k61948











  • No, it really isn't sic. It does do something in IPython
    – roganjosh
    Dec 7 at 20:15










  • I can run it in the IPython console and it forces a reset in Spyder
    – roganjosh
    Dec 7 at 20:16










  • No, it looks like this is right - the loop changes things in a way I didn't account for. I need to revise my answer a bit more.
    – user2357112
    Dec 7 at 20:16










  • @roganjosh Like it is doing what?
    – DYZ
    Dec 7 at 20:17






  • 1




    @roganjosh Pretty much so. Just like any other reference to an object or a function.
    – DYZ
    Dec 7 at 20:22
















  • No, it really isn't sic. It does do something in IPython
    – roganjosh
    Dec 7 at 20:15










  • I can run it in the IPython console and it forces a reset in Spyder
    – roganjosh
    Dec 7 at 20:16










  • No, it looks like this is right - the loop changes things in a way I didn't account for. I need to revise my answer a bit more.
    – user2357112
    Dec 7 at 20:16










  • @roganjosh Like it is doing what?
    – DYZ
    Dec 7 at 20:17






  • 1




    @roganjosh Pretty much so. Just like any other reference to an object or a function.
    – DYZ
    Dec 7 at 20:22















No, it really isn't sic. It does do something in IPython
– roganjosh
Dec 7 at 20:15




No, it really isn't sic. It does do something in IPython
– roganjosh
Dec 7 at 20:15












I can run it in the IPython console and it forces a reset in Spyder
– roganjosh
Dec 7 at 20:16




I can run it in the IPython console and it forces a reset in Spyder
– roganjosh
Dec 7 at 20:16












No, it looks like this is right - the loop changes things in a way I didn't account for. I need to revise my answer a bit more.
– user2357112
Dec 7 at 20:16




No, it looks like this is right - the loop changes things in a way I didn't account for. I need to revise my answer a bit more.
– user2357112
Dec 7 at 20:16












@roganjosh Like it is doing what?
– DYZ
Dec 7 at 20:17




@roganjosh Like it is doing what?
– DYZ
Dec 7 at 20:17




1




1




@roganjosh Pretty much so. Just like any other reference to an object or a function.
– DYZ
Dec 7 at 20:22




@roganjosh Pretty much so. Just like any other reference to an object or a function.
– DYZ
Dec 7 at 20:22










up vote
3
down vote













On my simple test,

Cell 1
a = 3

Cell 2
exit

cell 3
print(a)



resulted in



---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-3f786850e387> in <module>
----> 1 a

NameError: name 'a' is not defined


exit just kills the kernel that the notebook is relying on for execution.



Interestingly enough however, There seems to be a parameter you can pass to modify that behaviour as well.



Test 2:
Cell 1
a = 3

Cell 2
exit(keep_kernel=True)

cell 3
print(a)
resulted in
3



EDIT: And looks like @user2357112's answer fills in the missing pieces.

EDIT2: Actually, it seems to be an instance of IPython.core.autocall.ZMQExitAutocall



 class IPython.core.autocall.ZMQExitAutocall(ip=None)

Bases: IPython.core.autocall.ExitAutocall

Exit IPython. Autocallable, so it needn’t be explicitly called.
Parameters: keep_kernel (bool) – If True, leave the kernel alive. Otherwise, tell the kernel to exit too (default).





share|improve this answer






















  • Ah nice. I was trying to work out what this might do. So it looks like, from your test, it wipes the namespace?
    – roganjosh
    Dec 7 at 20:03






  • 1




    In Spyder it is restarting the IPython kernel. You already have my upvote, but I think you could do with adding the documentation for this (my lame way of backing out of a fiddly google search :P)
    – roganjosh
    Dec 7 at 20:05






  • 2




    mhm, i am actually really intrigued by this behaviour, tracking down the documentation atm, however check the edit. @roganjosh It makes me suspect it is doing something not just with namespaces.
    – Paritosh Singh
    Dec 7 at 20:07














up vote
3
down vote













On my simple test,

Cell 1
a = 3

Cell 2
exit

cell 3
print(a)



resulted in



---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-3f786850e387> in <module>
----> 1 a

NameError: name 'a' is not defined


exit just kills the kernel that the notebook is relying on for execution.



Interestingly enough however, There seems to be a parameter you can pass to modify that behaviour as well.



Test 2:
Cell 1
a = 3

Cell 2
exit(keep_kernel=True)

cell 3
print(a)
resulted in
3



EDIT: And looks like @user2357112's answer fills in the missing pieces.

EDIT2: Actually, it seems to be an instance of IPython.core.autocall.ZMQExitAutocall



 class IPython.core.autocall.ZMQExitAutocall(ip=None)

Bases: IPython.core.autocall.ExitAutocall

Exit IPython. Autocallable, so it needn’t be explicitly called.
Parameters: keep_kernel (bool) – If True, leave the kernel alive. Otherwise, tell the kernel to exit too (default).





share|improve this answer






















  • Ah nice. I was trying to work out what this might do. So it looks like, from your test, it wipes the namespace?
    – roganjosh
    Dec 7 at 20:03






  • 1




    In Spyder it is restarting the IPython kernel. You already have my upvote, but I think you could do with adding the documentation for this (my lame way of backing out of a fiddly google search :P)
    – roganjosh
    Dec 7 at 20:05






  • 2




    mhm, i am actually really intrigued by this behaviour, tracking down the documentation atm, however check the edit. @roganjosh It makes me suspect it is doing something not just with namespaces.
    – Paritosh Singh
    Dec 7 at 20:07












up vote
3
down vote










up vote
3
down vote









On my simple test,

Cell 1
a = 3

Cell 2
exit

cell 3
print(a)



resulted in



---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-3f786850e387> in <module>
----> 1 a

NameError: name 'a' is not defined


exit just kills the kernel that the notebook is relying on for execution.



Interestingly enough however, There seems to be a parameter you can pass to modify that behaviour as well.



Test 2:
Cell 1
a = 3

Cell 2
exit(keep_kernel=True)

cell 3
print(a)
resulted in
3



EDIT: And looks like @user2357112's answer fills in the missing pieces.

EDIT2: Actually, it seems to be an instance of IPython.core.autocall.ZMQExitAutocall



 class IPython.core.autocall.ZMQExitAutocall(ip=None)

Bases: IPython.core.autocall.ExitAutocall

Exit IPython. Autocallable, so it needn’t be explicitly called.
Parameters: keep_kernel (bool) – If True, leave the kernel alive. Otherwise, tell the kernel to exit too (default).





share|improve this answer














On my simple test,

Cell 1
a = 3

Cell 2
exit

cell 3
print(a)



resulted in



---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-3f786850e387> in <module>
----> 1 a

NameError: name 'a' is not defined


exit just kills the kernel that the notebook is relying on for execution.



Interestingly enough however, There seems to be a parameter you can pass to modify that behaviour as well.



Test 2:
Cell 1
a = 3

Cell 2
exit(keep_kernel=True)

cell 3
print(a)
resulted in
3



EDIT: And looks like @user2357112's answer fills in the missing pieces.

EDIT2: Actually, it seems to be an instance of IPython.core.autocall.ZMQExitAutocall



 class IPython.core.autocall.ZMQExitAutocall(ip=None)

Bases: IPython.core.autocall.ExitAutocall

Exit IPython. Autocallable, so it needn’t be explicitly called.
Parameters: keep_kernel (bool) – If True, leave the kernel alive. Otherwise, tell the kernel to exit too (default).






share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 7 at 20:18

























answered Dec 7 at 20:02









Paritosh Singh

74112




74112











  • Ah nice. I was trying to work out what this might do. So it looks like, from your test, it wipes the namespace?
    – roganjosh
    Dec 7 at 20:03






  • 1




    In Spyder it is restarting the IPython kernel. You already have my upvote, but I think you could do with adding the documentation for this (my lame way of backing out of a fiddly google search :P)
    – roganjosh
    Dec 7 at 20:05






  • 2




    mhm, i am actually really intrigued by this behaviour, tracking down the documentation atm, however check the edit. @roganjosh It makes me suspect it is doing something not just with namespaces.
    – Paritosh Singh
    Dec 7 at 20:07
















  • Ah nice. I was trying to work out what this might do. So it looks like, from your test, it wipes the namespace?
    – roganjosh
    Dec 7 at 20:03






  • 1




    In Spyder it is restarting the IPython kernel. You already have my upvote, but I think you could do with adding the documentation for this (my lame way of backing out of a fiddly google search :P)
    – roganjosh
    Dec 7 at 20:05






  • 2




    mhm, i am actually really intrigued by this behaviour, tracking down the documentation atm, however check the edit. @roganjosh It makes me suspect it is doing something not just with namespaces.
    – Paritosh Singh
    Dec 7 at 20:07















Ah nice. I was trying to work out what this might do. So it looks like, from your test, it wipes the namespace?
– roganjosh
Dec 7 at 20:03




Ah nice. I was trying to work out what this might do. So it looks like, from your test, it wipes the namespace?
– roganjosh
Dec 7 at 20:03




1




1




In Spyder it is restarting the IPython kernel. You already have my upvote, but I think you could do with adding the documentation for this (my lame way of backing out of a fiddly google search :P)
– roganjosh
Dec 7 at 20:05




In Spyder it is restarting the IPython kernel. You already have my upvote, but I think you could do with adding the documentation for this (my lame way of backing out of a fiddly google search :P)
– roganjosh
Dec 7 at 20:05




2




2




mhm, i am actually really intrigued by this behaviour, tracking down the documentation atm, however check the edit. @roganjosh It makes me suspect it is doing something not just with namespaces.
– Paritosh Singh
Dec 7 at 20:07




mhm, i am actually really intrigued by this behaviour, tracking down the documentation atm, however check the edit. @roganjosh It makes me suspect it is doing something not just with namespaces.
– Paritosh Singh
Dec 7 at 20:07

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53676034%2fwhat-does-exit-keyword-do-in-python3-with-jupyter-notebook%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?