-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
8ea21f5
commit f7232fd
Showing
6 changed files
with
103 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from artiq.coredevice.runtime_exceptions import exception_map, _RPCException | ||
|
||
|
||
def _lookup_exception(d, e): | ||
for eid, exception in d.items(): | ||
if isinstance(e, exception): | ||
return eid | ||
return 0 | ||
|
||
|
||
class RPCWrapper: | ||
def __init__(self): | ||
self.last_exception = None | ||
|
||
def run_rpc(self, user_exception_map, fn, args): | ||
eid = 0 | ||
r = None | ||
|
||
try: | ||
r = fn(*args) | ||
except Exception as e: | ||
eid = _lookup_exception(user_exception_map, e) | ||
if not eid: | ||
eid = _lookup_exception(exception_map, e) | ||
if eid: | ||
self.last_exception = None | ||
else: | ||
self.last_exception = e | ||
eid = _RPCException.eid | ||
|
||
if r is None: | ||
r = 0 | ||
else: | ||
r = int(r) | ||
|
||
return eid, r | ||
|
||
def filter_rpc_exception(self, eid): | ||
if eid == _RPCException.eid: | ||
raise self.last_exception |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters