Skip to content

KernelClient.execute() does not seem to process user expressions #678

Description

@smathot

KernelClient.execute() takes a user_expressions keyword that allows you to pass expressions that are evaluated in the background (i.e. you don't see them visually in the console) and then returned as part of the message.

This doesn't seem to work with ir-kernel though.

# This gets the third RichJupyterWidget of the Rapunzel console tabs. In this case running
# an ir-kernel
jc = JupyterConsole._jupyter_console.widget(2)._jupyter_widget
jc._handle_execute_reply = lambda msg: print(msg)
jc._kernel_client.execute('', silent=True, user_expressions={'test': '10 + 10'})

This returns the message id (e155cc54-78cd13ae0ceb85092a442156_18) and also captures the actual message, which is the following (and does not contain any user_expressions information):

{'header': {'msg_id': '2054f453-4f51-4b1b-82df-92b673da5cdb', 'username': 'sebastiaan', 'session': 'e155cc54-78cd13ae0ceb85092a442156', 'msg_type': 'execute_reply', 'version': '5.0', 'date': datetime.datetime(2021, 2, 28, 14, 59, 31, 776265, tzinfo=datetime.timezone.utc)}, 'msg_id': '2054f453-4f51-4b1b-82df-92b673da5cdb', 'msg_type': 'execute_reply', 'parent_header': {'msg_id': 'e155cc54-78cd13ae0ceb85092a442156_18', 'msg_type': 'execute_request', 'username': 'sebastiaan', 'session': 'e155cc54-78cd13ae0ceb85092a442156', 'date': datetime.datetime(2021, 2, 28, 14, 59, 31, 757084, tzinfo=tzutc()), 'version': '5.3'}, 'metadata': {}, 'content': {'status': 'ok', 'execution_count': 3, 'payload': [], 'user_expressions': {}}, 'buffers': []}

When doing the same with a python kernel, the returned message does include user_expressions information:

{'header': {'msg_id': 'f3370870-6796daf5119a84aab2717f22_17', 'msg_type': 'execute_reply', 'username': 'sebastiaan', 'session': 'f3370870-6796daf5119a84aab2717f22', 'date': datetime.datetime(2021, 2, 28, 14, 59, 46, 148023, tzinfo=tzutc()), 'version': '5.3'}, 'msg_id': 'f3370870-6796daf5119a84aab2717f22_17', 'msg_type': 'execute_reply', 'parent_header': {'msg_id': 'c56c89f3-dfcfc44a00917adcac27d97f_5', 'msg_type': 'execute_request', 'username': 'sebastiaan', 'session': 'c56c89f3-dfcfc44a00917adcac27d97f', 'date': datetime.datetime(2021, 2, 28, 14, 59, 46, 142819, tzinfo=tzutc()), 'version': '5.3'}, 'metadata': {'started': '2021-02-28T14:59:46.146066Z', 'dependencies_met': True, 'engine': 'edf495dd-2520-4ff6-864d-1771a4ac7261', 'status': 'ok'}, 'content': {'status': 'ok', 'execution_count': 0, 'user_expressions': {'test': {'status': 'ok', 'data': {'text/plain': '20'}, 'metadata': {}}}, 'payload': []}, 'buffers': []}

I would like to use these user expressions to expose the kernel workspace to the workspace explorer of Rapunzel. Is this possible? Or, if it's not, is there another way in which I can get the R workspace from the kernel into Python?

(And also: great work! 👍 )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions