Pyhass / Pyhiveapi

A python library to interface with the hive home api
MIT License
23 stars 16 forks source link

[BUG] unasync'd HiveSession.updateData generates warnings and exceptions on lock acquisition / release #74

Closed gormanb closed 7 hours ago

gormanb commented 5 months ago

Describe the bug When pyhiveapi is packaged via unasync, it removes the await from this asyncio.Lock acquisition in HiveSession.updateData but otherwise leaves the asyncio.Lock in place. As a result, calling updateData generates the following warning:

/path/to/session.py:328: RuntimeWarning: coroutine 'Lock.acquire' was never awaited
  self.updateLock.acquire()

... and can throw the following exception if it attempts to release the lock without having acquired it:

[1/13/2024, 2:20:09 PM] Error: Python exception: Lock is not acquired.

Expected behavior Calling HiveSession.updateData succeeds without spurious warning or errors.

Additional context I have a patch here which simply adds an unasync rule to convert the asyncio.Lock in session.py to threading.Lock instead. No other code is affected by this change. I can open a PR, if you think this is an appropriate solution?

Khole-FG commented 5 months ago

@gormanb Yes please raise a pr for this

gormanb commented 5 months ago

@gormanb Yes please raise a pr for this

Done!

gormanb commented 7 hours ago

Fixed by PR #75 in commit b3ee963.