Skip to content

Commit

Permalink
Add a test for traceback and update wiki
Browse files Browse the repository at this point in the history
Signed-off-by: Gajowniczek, Artur <artur.gajowniczek@point72.com>
  • Loading branch information
argaj committed Jul 12, 2024
1 parent 4ddc99f commit ddd1c3a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
12 changes: 9 additions & 3 deletions csp/tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,8 +825,10 @@ def stop(self):
pass

def process_next_sim_timeslice(self, now):
self.shutdown_engine(ValueError("Dummy exception message"))

try:
[].pop()
except IndexError as e:
self.shutdown_engine(e)
class TestAdapterImpl(ManagedSimInputAdapter):
def __init__(self, manager_impl):
pass
Expand All @@ -838,8 +840,12 @@ def graph():
nc = adapter.subscribe()
csp.add_graph_output("nc", nc)

with self.assertRaisesRegex(ValueError, "Dummy exception message"):
try:
csp.run(graph, starttime=datetime(2020, 1, 1), endtime=timedelta(seconds=1))
except IndexError:
tb = traceback.format_exc()

self.assertTrue('[].pop()' in tb)

def test_feedback(self):
# Dummy example
Expand Down
15 changes: 15 additions & 0 deletions docs/wiki/how-tos/Write-Realtime-Input-Adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,18 @@ csp.run(my_graph, starttime=datetime.utcnow(), endtime=timedelta(seconds=10), re
```

Do note that realtime adapters will only run in realtime engines (note the `realtime=True` argument to `csp.run`).

## Engine shutdown

In case a pushing thread hits a terminal error, an exception can be passed to the main engine thread to shut down gracefully through a `shutdown_engine(exc: Exception)` method exposed by `PushInputAdapter`, `PushPullInputAdapter` and `AdapterManagerImpl`.

For example:

```python
def _run(self):
while self._running:
try:
requests.get(endpoint) # API call over a network, may fail
catch Exception as exc:
self.shutdown_engine(exc)
```

0 comments on commit ddd1c3a

Please sign in to comment.