@@ -298,7 +298,13 @@ impl DurationLike {
298
298
fn into_duration ( self ) -> Duration {
299
299
match self {
300
300
Self :: Int ( i) => Duration :: from_secs ( i as u64 ) ,
301
- Self :: Float ( f) => Duration :: from_secs_f64 ( f) ,
301
+ Self :: Float ( f) => match duration_from_sec ( f) {
302
+ Ok ( duration) => duration,
303
+ Err ( err) => {
304
+ re_log:: error_once!( "{err}" ) ;
305
+ Duration :: ZERO
306
+ }
307
+ } ,
302
308
Self :: Duration ( d) => d,
303
309
}
304
310
}
@@ -1374,7 +1380,7 @@ impl PyBinarySinkStorage {
1374
1380
// Release the GIL in case any flushing behavior needs to cleanup a python object.
1375
1381
py. allow_threads ( || -> PyResult < _ > {
1376
1382
if flush {
1377
- let timeout = timeout_from_sec ( flush_timeout_sec) ?;
1383
+ let timeout = duration_from_sec ( flush_timeout_sec as _ ) ?;
1378
1384
self . inner
1379
1385
. flush ( timeout)
1380
1386
. map_err ( |err| PyRuntimeError :: new_err ( err. to_string ( ) ) ) ?;
@@ -1405,7 +1411,7 @@ impl PyBinarySinkStorage {
1405
1411
fn flush ( & self , py : Python < ' _ > , timeout_sec : f32 ) -> PyResult < ( ) > {
1406
1412
// Release the GIL in case any flushing behavior needs to cleanup a python object.
1407
1413
py. allow_threads ( || -> PyResult < _ > {
1408
- let timeout = timeout_from_sec ( timeout_sec) ?;
1414
+ let timeout = duration_from_sec ( timeout_sec as _ ) ?;
1409
1415
self . inner
1410
1416
. flush ( timeout)
1411
1417
. map_err ( |err| PyRuntimeError :: new_err ( err. to_string ( ) ) ) ?;
@@ -1415,13 +1421,13 @@ impl PyBinarySinkStorage {
1415
1421
}
1416
1422
}
1417
1423
1418
- fn timeout_from_sec ( seconds : f32 ) -> PyResult < Duration > {
1424
+ fn duration_from_sec ( seconds : f64 ) -> PyResult < Duration > {
1419
1425
if seconds. is_nan ( ) {
1420
- Err ( PyRuntimeError :: new_err ( "timeout_sec must not be NaN" ) )
1426
+ Err ( PyRuntimeError :: new_err ( "duration must not be NaN" ) )
1421
1427
} else if seconds < 0.0 {
1422
- Err ( PyRuntimeError :: new_err ( "timeout_sec must be non-negative" ) )
1428
+ Err ( PyRuntimeError :: new_err ( "duration must be non-negative" ) )
1423
1429
} else {
1424
- Ok ( Duration :: try_from_secs_f32 ( seconds) . unwrap_or ( Duration :: MAX ) )
1430
+ Ok ( Duration :: try_from_secs_f64 ( seconds) . unwrap_or ( Duration :: MAX ) )
1425
1431
}
1426
1432
}
1427
1433
@@ -1607,24 +1613,33 @@ fn disconnect(py: Python<'_>, recording: Option<&PyRecordingStream>) {
1607
1613
}
1608
1614
1609
1615
/// Block until outstanding data has been flushed to the sink.
1616
+ // TODO(#11294): remove `blocking` argument and put the `*` first
1610
1617
#[ pyfunction]
1611
- #[ pyo3( signature = ( blocking, recording=None ) ) ]
1612
- fn flush ( py : Python < ' _ > , blocking : bool , recording : Option < & PyRecordingStream > ) -> PyResult < ( ) > {
1618
+ #[ pyo3( signature = ( blocking = true , recording = None , * , timeout_sec = 1e38 ) ) ] // Can't use infinity here because of python_check_signatures.py
1619
+ fn flush (
1620
+ py : Python < ' _ > ,
1621
+ blocking : bool ,
1622
+ recording : Option < & PyRecordingStream > ,
1623
+ timeout_sec : f32 ,
1624
+ ) -> PyResult < ( ) > {
1613
1625
let Some ( recording) = get_data_recording ( recording) else {
1614
1626
return Ok ( ( ) ) ;
1615
1627
} ;
1616
1628
1617
1629
// Release the GIL in case any flushing behavior needs to cleanup a python object.
1618
- py. allow_threads ( || -> Result < ( ) , SinkFlushError > {
1619
- if blocking {
1620
- recording. flush_blocking ( ) ?;
1630
+ py. allow_threads ( || -> PyResult < ( ) > {
1631
+ if !blocking || timeout_sec == 0.0 {
1632
+ recording
1633
+ . flush_async ( )
1634
+ . map_err ( |err : SinkFlushError | PyRuntimeError :: new_err ( err. to_string ( ) ) ) ?;
1621
1635
} else {
1622
- recording. flush_async ( ) ?;
1636
+ recording
1637
+ . flush_with_timeout ( duration_from_sec ( timeout_sec as _ ) ?)
1638
+ . map_err ( |err : SinkFlushError | PyRuntimeError :: new_err ( err. to_string ( ) ) ) ?;
1623
1639
}
1624
1640
flush_garbage_queue ( ) ;
1625
1641
Ok ( ( ) )
1626
1642
} )
1627
- . map_err ( |err : SinkFlushError | PyRuntimeError :: new_err ( err. to_string ( ) ) )
1628
1643
}
1629
1644
1630
1645
// --- Components ---
0 commit comments