Skip to content

Commit 5c77a1b

Browse files
committed
fix integer engine id in exception metadata
was using old int_id which is just -1
1 parent 42be42d commit 5c77a1b

File tree

2 files changed

+71
-6
lines changed

2 files changed

+71
-6
lines changed

ipyparallel/engine/kernel.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""IPython kernel for parallel computing"""
2+
import inspect
23
import sys
34

45
from ipykernel.ipkernel import IPythonKernel
@@ -15,6 +16,11 @@ class IPythonParallelKernel(IPythonKernel):
1516
"""Extend IPython kernel for parallel computing"""
1617

1718
engine_id = Integer(-1)
19+
20+
@property
21+
def int_id(self):
22+
return self.engine_id
23+
1824
msg_types = getattr(IPythonKernel, 'msg_types', []) + ['apply_request']
1925
control_msg_types = getattr(IPythonKernel, 'control_msg_types', []) + [
2026
'abort_request',
@@ -78,13 +84,20 @@ def finish_metadata(self, parent, metadata, reply_content):
7884
if reply_content['status'] == 'error':
7985
if reply_content['ename'] == 'UnmetDependency':
8086
metadata['dependencies_met'] = False
81-
metadata['engine_info'] = dict(
82-
engine_uuid=self.ident,
83-
engine_id=self.engine_id,
84-
)
87+
metadata['engine_info'] = self.get_engine_info()
8588

8689
return metadata
8790

91+
def get_engine_info(self, method=None):
92+
"""Return engine_info dict"""
93+
engine_info = dict(
94+
engine_uuid=self.ident,
95+
engine_id=self.engine_id,
96+
)
97+
if method:
98+
engine_info["method"] = method
99+
return engine_info
100+
88101
def apply_request(self, stream, ident, parent):
89102
try:
90103
content = parent['content']
@@ -168,8 +181,7 @@ def do_apply(self, content, bufs, msg_id, reply_metadata):
168181
else:
169182
self.log.warning("Didn't find a traceback where I expected to")
170183
shell._last_traceback = None
171-
e_info = dict(engine_uuid=self.ident, engine_id=self.int_id, method='apply')
172-
reply_content['engine_info'] = e_info
184+
reply_content["engine_info"] = self.get_engine_info(method="apply")
173185

174186
self.log.info(
175187
"Exception in apply request:\n%s", '\n'.join(reply_content['traceback'])
@@ -181,6 +193,14 @@ def do_apply(self, content, bufs, msg_id, reply_metadata):
181193

182194
return reply_content, result_buf
183195

196+
async def do_execute(self, *args, **kwargs):
197+
reply_content = super().do_execute(*args, **kwargs)
198+
if inspect.isawaitable(reply_content):
199+
reply_content = await reply_content
200+
if reply_content['status'] == 'error':
201+
reply_content["engine_info"] = self.get_engine_info(method="execute")
202+
return reply_content
203+
184204
# Control messages for msgspec extensions:
185205

186206
def abort_request(self, stream, ident, parent):

ipyparallel/tests/test_asyncresult.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import time
66
from datetime import datetime
77

8+
import pytest
89
from IPython.utils.io import capture_output
910

1011
import ipyparallel as ipp
@@ -488,3 +489,47 @@ def test_progress(self):
488489
assert amr.progress == 0
489490
amr.wait_interactive()
490491
assert amr.progress == len(amr)
492+
493+
def test_error_engine_info_apply(self):
494+
dv = self.client[:]
495+
targets = self.client.ids
496+
ar = dv.apply_async(lambda: 1 / 0)
497+
try:
498+
ar.get()
499+
except Exception as e:
500+
exc = e
501+
else:
502+
pytest.fail("Should have raised remote ZeroDivisionError")
503+
assert isinstance(exc, ipp.error.CompositeError)
504+
expected_engine_info = [
505+
{
506+
"engine_id": engine_id,
507+
"engine_uuid": self.client._engines[engine_id],
508+
"method": "apply",
509+
}
510+
for engine_id in self.client.ids
511+
]
512+
engine_infos = [e[-1] for e in exc.elist]
513+
assert engine_infos == expected_engine_info
514+
515+
def test_error_engine_info_execute(self):
516+
dv = self.client[:]
517+
targets = self.client.ids
518+
ar = dv.execute("1 / 0", block=False)
519+
try:
520+
ar.get()
521+
except Exception as e:
522+
exc = e
523+
else:
524+
pytest.fail("Should have raised remote ZeroDivisionError")
525+
assert isinstance(exc, ipp.error.CompositeError)
526+
expected_engine_info = [
527+
{
528+
"engine_id": engine_id,
529+
"engine_uuid": self.client._engines[engine_id],
530+
"method": "execute",
531+
}
532+
for engine_id in self.client.ids
533+
]
534+
engine_infos = [e[-1] for e in exc.elist]
535+
assert engine_infos == expected_engine_info

0 commit comments

Comments
 (0)