23
23
_JListenerRecorder = jpy .get_type ("io.deephaven.engine.table.impl.ListenerRecorder" )
24
24
_JPythonMergedListenerAdapter = jpy .get_type ("io.deephaven.integrations.python.PythonMergedListenerAdapter" )
25
25
26
+ _DEFAULT_ON_ERROR_CALLBACK = lambda e : print (f"An error occurred during table update processing: { e } " )
26
27
27
28
class TableUpdate (JObjectWrapper ):
28
29
"""A TableUpdate object represents a table update event. It contains the added, removed, and modified rows in the
@@ -202,12 +203,9 @@ def on_error(self, e: Exception) -> None:
202
203
Args:
203
204
e (Exception): the exception that occurred during the listener's execution.
204
205
"""
205
- print (f"An error occurred during listener execution : { self } , { e } " )
206
+ print (f"An error occurred during table update processing : { self } , { e } " )
206
207
207
208
208
- def _default_on_error (e : Exception ) -> None :
209
- print (f"An error occurred during listener execution: { e } " )
210
-
211
209
def _listener_wrapper (table : Table ):
212
210
"""A decorator to wrap a user listener function or on_update method to receive the numpy-converted Table updates.
213
211
@@ -225,7 +223,6 @@ def wrapper(update, *args):
225
223
226
224
return decorator
227
225
228
-
229
226
def _wrap_listener_func (t : Table , listener : Callable [[TableUpdate , bool ], None ]):
230
227
n_params = len (signature (listener ).parameters )
231
228
if n_params != 2 :
@@ -248,6 +245,7 @@ def wrapper(e):
248
245
249
246
return wrapper
250
247
248
+
251
249
class TableListenerHandle (JObjectWrapper ):
252
250
"""A handle to manage a table listener's lifecycle."""
253
251
j_object_type = _JPythonReplayListenerAdapter
@@ -287,12 +285,11 @@ def __init__(self, t: Table, listener: Union[Callable[[TableUpdate, bool], None]
287
285
and then add the result tables as dependencies to the listener so that they can be safely read in it.
288
286
on_error (Callable[[Exception], None]): a callback function to be invoked when an error occurs during the
289
287
listener's execution. It should only be set when the listener is a function, not when it is an instance
290
- of TableListener. Defaults to None. When None, a default callback function will be provided that simply
288
+ of TableListener. When the listener is a TableListener, TableListener.on_error will be used.
289
+ Defaults to None. When None, a default callback function will be provided that simply
291
290
prints out the received exception. If the callback function itself raises an exception, the new exception
292
291
will be logged in the Deephaven server log and will not be further processed by the server.
293
292
294
-
295
-
296
293
Raises:
297
294
DHError
298
295
"""
@@ -313,7 +310,7 @@ def __init__(self, t: Table, listener: Union[Callable[[TableUpdate, bool], None]
313
310
if on_error :
314
311
on_error_callback = _error_callback_wrapper (on_error )
315
312
else :
316
- on_error_callback = _error_callback_wrapper (_default_on_error )
313
+ on_error_callback = _error_callback_wrapper (_DEFAULT_ON_ERROR_CALLBACK )
317
314
else :
318
315
raise DHError (message = "listener is neither callable nor TableListener object" )
319
316
@@ -390,11 +387,11 @@ def listen(t: Table, listener: Union[Callable[[TableUpdate, bool], None], TableL
390
387
and then add the result tables as dependencies to the listener so that they can be safely read in it.
391
388
on_error (Callable[[Exception], None]): a callback function to be invoked when an error occurs during the
392
389
listener's execution. It should only be set when the listener is a function, not when it is an instance
393
- of TableListener. Defaults to None. When None, a default callback function will be provided that simply
390
+ of TableListener. When the listener is a TableListener, TableListener.on_error will be used.
391
+ Defaults to None. When None, a default callback function will be provided that simply
394
392
prints out the received exception. If the callback function itself raises an exception, the new exception
395
393
will be logged in the Deephaven server log and will not be further processed by the server.
396
394
397
-
398
395
Returns:
399
396
a TableListenerHandle
400
397
@@ -452,7 +449,7 @@ def on_error(self, e: Exception) -> None:
452
449
Args:
453
450
e (Exception): the exception that occurred during the listener's execution.
454
451
"""
455
- print (f"An error occurred during listener execution : { self } , { e } " )
452
+ print (f"An error occurred during table update processing : { self } , { e } " )
456
453
457
454
458
455
class MergedListenerHandle (JObjectWrapper ):
@@ -499,11 +496,11 @@ def __init__(self, tables: Sequence[Table], listener: Union[Callable[[Dict[Table
499
496
and then add the result tables as dependencies to the listener so that they can be safely read in it.
500
497
on_error (Callable[[Exception], None]): a callback function to be invoked when an error occurs during the
501
498
listener's execution. It should only be set when the listener is a function, not when it is an instance
502
- of MergedListener. Defaults to None. When None, a default callback function will be provided that simply
499
+ of MergedListener. When the listener is a MergedListener, MergedListener.on_error will be used.
500
+ Defaults to None. When None, a default callback function will be provided that simply
503
501
prints out the received exception. If the callback function itself raises an exception, the new exception
504
502
will be logged in the Deephaven server log and will not be further processed by the server.
505
503
506
-
507
504
Raises:
508
505
DHError
509
506
"""
@@ -525,7 +522,7 @@ def __init__(self, tables: Sequence[Table], listener: Union[Callable[[Dict[Table
525
522
if on_error :
526
523
on_error_callback = _error_callback_wrapper (on_error )
527
524
else :
528
- on_error_callback = _error_callback_wrapper (_default_on_error )
525
+ on_error_callback = _error_callback_wrapper (_DEFAULT_ON_ERROR_CALLBACK )
529
526
else :
530
527
raise DHError (message = "listener is neither callable nor MergedListener object" )
531
528
@@ -625,7 +622,8 @@ def merged_listen(tables: Sequence[Table], listener: Union[Callable[[Dict[Table,
625
622
and then add the result tables as dependencies to the listener so that they can be safely read in it.
626
623
on_error (Callable[[Exception], None]): a callback function to be invoked when an error occurs during the
627
624
listener's execution. It should only be set when the listener is a function, not when it is an instance
628
- of MergedListener. Defaults to None. When None, a default callback function will be provided that simply
625
+ of MergedListener. When the listener is a MergedListener, MergedListener.on_error will be used.
626
+ Defaults to None. When None, a default callback function will be provided that simply
629
627
prints out the received exception. If the callback function itself raises an exception, the new exception
630
628
will be logged in the Deephaven server log and will not be further processed by the server.
631
629
"""
0 commit comments