Thanks Matthias, That is a very good explanation, I assume namespace that gets passed around only stores the named reference to objects and not the data itself.
Data and objects are in memory separately so it should be only limited by memory of server or is it limited by memory of python kernel? On Saturday, July 20, 2019 at 9:31:41 PM UTC-7, Matthias Bussonnier wrote: > > Hi Zweb1, > > THis is a really good question, > > We use Python built-in exec ( > https://docs.python.org/3/library/functions.html#exec), which allow you > to execute some code and pass a namespace in which to execute it. > You then put it in a while loop, and wait for the user to send some code. > Exec send the result back. > Here is a 5 lines REPL (read eval print loop) as example on how to > evaluate user code interactively. > > $ cat repl.py > > File: repl.py > 1 │ > 2 │ namespace = dict() > 3 │ > 4 │ > 5 │ while True: > 6 │ code = input('>>> ') > 7 │ exec(code, namespace) > > $ python repl.py > >>> a = 1 > >>> print(a) > 1 > >>> print(a+1) > 2 > >>> > > You you were to look at namespace, you would see that after a = 1, we have > namespace['a'] == 1, so the namespace dict hold all our variables between > exec. > > This +/- 40 000 lines of code give you IPython, there is a lot not handled > there, but if you take the above, handle exceptions, multiple > statements.... etc and forward stdin and out over the network you have a > rough prototype of what Jupyter is. > > Does that answer your question? > -- > Matthias > > On Sat, 20 Jul 2019 at 19:08, zweb1 <[email protected] <javascript:>> > wrote: > >> How does jupyter kernel maintain context of all the previous cell >> executions in a session? How is it implemented? >> >> example: >> >> cell [1]: import pandas >> >> cell[2]: x = 7 >> >> cell[3] print(x) >> >> 3 >> >> When executing cell 3, Jupyter Kernel has x from cell 2 and pandas import >> from cell 1 execution. How is it implemented in the kernel? >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Project Jupyter" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/jupyter/2312ef59-7f49-4ae4-927b-db278d69e35e%40googlegroups.com >> >> <https://groups.google.com/d/msgid/jupyter/2312ef59-7f49-4ae4-927b-db278d69e35e%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- You received this message because you are subscribed to the Google Groups "Project Jupyter" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/a17f7389-0fc0-4c4b-891f-b2debe17ba65%40googlegroups.com.
