From 7c121e482f6d60ae52676323ccd8a2a50a47e711 Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Mon, 9 Jan 2017 11:30:10 -0500 Subject: [PATCH 1/3] add optional timeout to handle() --- src/PyLCM.jl | 24 +++++++++++++++++++++++- test/runtests.jl | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/PyLCM.jl b/src/PyLCM.jl index 1b32369..19b193e 100644 --- a/src/PyLCM.jl +++ b/src/PyLCM.jl @@ -2,6 +2,7 @@ VERSION >= v"0.4.0-dev+6521" && __precompile__() module PyLCM +using Base.Dates: Period, Millisecond using PyCall export LCM, publish, subscribe, handle, @pyimport @@ -25,8 +26,29 @@ function subscribe(lc::LCM, channel::AbstractString, handler::Function, msg_type lc.lcm_obj[:subscribe](channel, pyeval("lambda chan, data, handler=h, msg_type=t: handler(chan, msg_type.decode(data))", h=handler, t=msg_type)) end +"Wait for and dispatch the next incoming message" function handle(lc::LCM) - pycall(lc.lcm_obj[:handle], PyObject) + pycall(lc.lcm_obj[:handle], PyObject) + nothing +end + +""" + handle(lc, timeout) + +Wait for and dispatch the next incoming message, with a timeout expressed +as any Base.Dates.Period type. For example: + + handle(lc, Millisecond(10)) + +or + + handle(lc, Second(1)) + +Returns true if a message was handled, false if the function timed out. +""" +function handle(lc::LCM, timeout::Period) + timeout_ms = convert(Int, convert(Millisecond, timeout)) + convert(Bool, pycall(lc.lcm_obj[:handle_timeout], PyObject, timeout_ms)) end function __init__() diff --git a/test/runtests.jl b/test/runtests.jl index 7e48789..72db3b8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -54,5 +54,5 @@ end subscribe(lc, "TEST_DECODE", decode_and_handle_msg) publish(lc, "TEST_DECODE", msg) -handle(lc) +handle(lc, Dates.Second(1)) @test decoded_message From c3762c8b0ba86ba88b564a6d3130514ea5229792 Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Mon, 9 Jan 2017 11:37:18 -0500 Subject: [PATCH 2/3] handle() always returns bool, regardless of whether timeout was given --- src/PyLCM.jl | 4 ++-- test/runtests.jl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/PyLCM.jl b/src/PyLCM.jl index 19b193e..7b92ae5 100644 --- a/src/PyLCM.jl +++ b/src/PyLCM.jl @@ -1,4 +1,4 @@ -VERSION >= v"0.4.0-dev+6521" && __precompile__() +__precompile__() module PyLCM @@ -29,7 +29,7 @@ end "Wait for and dispatch the next incoming message" function handle(lc::LCM) pycall(lc.lcm_obj[:handle], PyObject) - nothing + true end """ diff --git a/test/runtests.jl b/test/runtests.jl index 72db3b8..6411047 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -34,7 +34,7 @@ end subscribe(lc, "TEST", handle_msg, pylcm_test_message.multidimensional_array_t) publish(lc, "TEST", msg) -handle(lc) +@test handle(lc) @test got_message global decoded_message = false @@ -54,5 +54,5 @@ end subscribe(lc, "TEST_DECODE", decode_and_handle_msg) publish(lc, "TEST_DECODE", msg) -handle(lc, Dates.Second(1)) +@test handle(lc, Dates.Second(1)) @test decoded_message From daf2d2bc27ec221690ccf3bdd49412b13ee4435b Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Mon, 9 Jan 2017 11:39:18 -0500 Subject: [PATCH 3/3] allow nightly to fail --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index fc6dbd1..742fe98 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,9 @@ notifications: branches: only: - master +matrix: + allow_failures: + - julia: nightly after_success: - julia -e 'cd(Pkg.dir("PyLCM")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())'