@@ -133,7 +133,7 @@ def __init__(self, main, *args, **kwargs):
133
133
self .kernel_manager = kernel_manager
134
134
self .kernel_client = kernel_client
135
135
136
- self .kernel_manager . kernel . shell . run_code (
136
+ self .run_command_in_shell (
137
137
'\n ' .join ('import %s as %s' % t for t in modules2import ))
138
138
self .exit_requested .connect (self ._close_mainwindow )
139
139
self .exit_requested .connect (QtCore .QCoreApplication .instance ().quit )
@@ -166,13 +166,13 @@ def update_mp(self, project):
166
166
"""Update the `mp` variable in the shell is
167
167
``rcParams['console.auto_set_mp']`` with a main project"""
168
168
if self .rc ['auto_set_mp' ] and project is not None and project .is_main :
169
- self .kernel_manager . kernel . shell . run_code ('mp = psy.gcp(True)' )
169
+ self .run_command_in_shell ('mp = psy.gcp(True)' )
170
170
171
171
def update_sp (self , project ):
172
172
"""Update the `sp` variable in the shell is
173
173
``rcParams['console.auto_set_sp']`` with a sub project"""
174
174
if self .rc ['auto_set_sp' ] and (project is None or not project .is_main ):
175
- self .kernel_manager . kernel . shell . run_code ('sp = psy.gcp()' )
175
+ self .run_command_in_shell ('sp = psy.gcp()' )
176
176
177
177
def show_current_help (self , to_end = False , force = False ):
178
178
"""Show the help of the object at the cursor position if
@@ -271,9 +271,18 @@ def _run_command_in_shell(self, args):
271
271
# 2: command
272
272
self .run_command_in_shell (args [2 ])
273
273
274
- def run_command_in_shell (self , command ):
274
+ def run_command_in_shell (self , code , * args , ** kwargs ):
275
275
"""Run a script in the shell"""
276
- self .kernel_manager .kernel .shell .run_code (command )
276
+ ret = self .kernel_manager .kernel .shell .run_code (code , * args , ** kwargs )
277
+ import IPython
278
+ if IPython .__version__ < '7.0' : # run_code is an asyncio.coroutine
279
+ return ret
280
+ else :
281
+ import asyncio
282
+ gathered = asyncio .gather (ret )
283
+ loop = asyncio .get_event_loop ()
284
+ ret = loop .run_until_complete (gathered )
285
+ return ret [0 ]
277
286
278
287
def _close_mainwindow (self ):
279
288
from psyplot_gui .main import mainwindow
0 commit comments