params: add put_bool_nonblocking (#25292)

* add bool flag

* cleanup

Co-authored-by: Willem Melching <willem.melching@gmail.com>
This commit is contained in:
ZwX1616 2022-07-28 13:17:11 -07:00 committed by GitHub
parent e77dc1ab44
commit 1f087bceb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 9 deletions

View File

@ -1,8 +1,9 @@
from common.params_pyx import Params, ParamKeyType, UnknownKeyName, put_nonblocking # pylint: disable=no-name-in-module, import-error
from common.params_pyx import Params, ParamKeyType, UnknownKeyName, put_nonblocking, put_bool_nonblocking # pylint: disable=no-name-in-module, import-error
assert Params
assert ParamKeyType
assert UnknownKeyName
assert put_nonblocking
assert put_bool_nonblocking
if __name__ == "__main__":
import sys

View File

@ -100,11 +100,7 @@ cdef class Params:
return self.p.getParamPath(key_bytes).decode("utf-8")
def put_nonblocking(key, val, d=""):
def f(key, val):
params = Params(d)
cdef string k = ensure_bytes(key)
params.put(k, val)
threading.Thread(target=lambda: Params(d).put(key, val)).start()
t = threading.Thread(target=f, args=(key, val))
t.start()
return t
def put_bool_nonblocking(key, bool val, d=""):
threading.Thread(target=lambda: Params(d).put_bool(key, val)).start()

View File

@ -4,7 +4,7 @@ import tempfile
import shutil
import unittest
from common.params import Params, ParamKeyType, UnknownKeyName, put_nonblocking
from common.params import Params, ParamKeyType, UnknownKeyName, put_nonblocking, put_bool_nonblocking
class TestParams(unittest.TestCase):
def setUp(self):
@ -89,6 +89,15 @@ class TestParams(unittest.TestCase):
assert q.get("CarParams") is None
assert q.get("CarParams", True) == b"test"
def test_put_bool_non_blocking_with_get_block(self):
q = Params(self.tmpdir)
def _delayed_writer():
time.sleep(0.1)
put_bool_nonblocking("CarParams", True, self.tmpdir)
threading.Thread(target=_delayed_writer).start()
assert q.get("CarParams") is None
assert q.get("CarParams", True) == b"1"
if __name__ == "__main__":
unittest.main()