@@ -5,6 +5,9 @@ import jupyter.kotlin.DependsOn
55import jupyter.kotlin.KotlinContext
66import jupyter.kotlin.KotlinKernelHostProvider
77import jupyter.kotlin.Repository
8+ import kotlinx.coroutines.Dispatchers
9+ import kotlinx.coroutines.GlobalScope
10+ import kotlinx.coroutines.launch
811import org.jetbrains.annotations.TestOnly
912import org.jetbrains.kotlin.config.KotlinCompilerVersion
1013import org.jetbrains.kotlinx.jupyter.api.Code
@@ -136,7 +139,8 @@ interface ReplForJupyter {
136139
137140 suspend fun serializeVariables (cellId : Int , descriptorsState : Map <String , SerializedVariablesState >, callback : (SerializationReply ) -> Unit )
138141
139- suspend fun serializeVariables (topLevelVarName : String , descriptorsState : Map <String , SerializedVariablesState >, callback : (SerializationReply ) -> Unit )
142+ suspend fun serializeVariables (topLevelVarName : String , descriptorsState : Map <String , SerializedVariablesState >, pathToDescriptor : List <String > = emptyList(),
143+ callback : (SerializationReply ) -> Unit )
140144
141145 val homeDir: File ?
142146
@@ -209,7 +213,7 @@ class ReplForJupyterImpl(
209213
210214 override val variablesSerializer = VariablesSerializer ()
211215
212- private val librariesScanner = LibrariesScanner (notebook)
216+ val librariesScanner = LibrariesScanner (notebook)
213217 private val resourcesProcessor = LibraryResourcesProcessorImpl ()
214218
215219 override var outputConfig
@@ -455,8 +459,10 @@ class ReplForJupyterImpl(
455459 // printUsagesInfo(jupyterId, cellVariables[jupyterId - 1])
456460 val serializedData = variablesSerializer.serializeVariables(jupyterId - 1 , notebook.variablesState, notebook.unchangedVariables())
457461
462+ GlobalScope .launch(Dispatchers .Default ) {
463+ variablesSerializer.tryValidateCache(jupyterId - 1 , notebook.cellVariables)
464+ }
458465
459- val variablesStateUpdate = notebook.variablesState.mapValues { " " }
460466 EvalResultEx (
461467 result.result.value,
462468 rendered,
@@ -559,8 +565,9 @@ class ReplForJupyterImpl(
559565 doWithLock(SerializationArgs (descriptorsState, cellId = cellId, callback = callback), serializationQueue, SerializationReply (cellId, descriptorsState), ::doSerializeVariables)
560566 }
561567
562- override suspend fun serializeVariables (topLevelVarName : String , descriptorsState : Map <String , SerializedVariablesState >, callback : (SerializationReply ) -> Unit ) {
563- doWithLock(SerializationArgs (descriptorsState, topLevelVarName = topLevelVarName, callback = callback), serializationQueue, SerializationReply (), ::doSerializeVariables)
568+ override suspend fun serializeVariables (topLevelVarName : String , descriptorsState : Map <String , SerializedVariablesState >, pathToDescriptor : List <String >,
569+ callback : (SerializationReply ) -> Unit ) {
570+ doWithLock(SerializationArgs (descriptorsState, topLevelVarName = topLevelVarName, callback = callback, pathToDescriptor = pathToDescriptor), serializationQueue, SerializationReply (), ::doSerializeVariables)
564571 }
565572
566573 private fun doSerializeVariables (args : SerializationArgs ): SerializationReply {
@@ -571,7 +578,7 @@ class ReplForJupyterImpl(
571578 finalAns
572579 }
573580 args.descriptorsState.forEach { (name, state) ->
574- resultMap[name] = variablesSerializer.doIncrementalSerialization(cellId - 1 , name, state)
581+ resultMap[name] = variablesSerializer.doIncrementalSerialization(cellId - 1 , name, state, args.pathToDescriptor )
575582 }
576583 log.debug(" Serialization cellID: $cellId " )
577584 log.debug(" Serialization answer: ${resultMap.entries.first().value.fieldDescriptor} " )
@@ -615,6 +622,7 @@ class ReplForJupyterImpl(
615622 val descriptorsState : Map <String , SerializedVariablesState >,
616623 var cellId : Int = -1 ,
617624 val topLevelVarName : String = " " ,
625+ val pathToDescriptor : List <String > = emptyList(),
618626 override val callback : (SerializationReply ) -> Unit
619627 ) : LockQueueArgs<SerializationReply>
620628
0 commit comments