audiokinetic / waapi-client-python

Decoupled autobahn WAMP client with support for plain options and bindable subscription callbacks
Apache License 2.0
42 stars 6 forks source link

Pull Request about event-loop crash #11

Open kakyoism opened 3 years ago

kakyoism commented 3 years ago

Hello AK,

Thanks for the ongoing improvent happening in WAAPI client. This is a pull request regarding a recent issue I bumped into: https://github.com/audiokinetic/waapi-client-python/pull/10

Please feel free to take a look! Cheers!

ak-slongchamps commented 3 years ago

Hi @kakyoism , thanks for the pull request!

Is this issue new in 0.6? Also, could you elaborate on the situation where the RuntimeError is triggered? If you have a minimal repro script, I better review the change and hopefully add meaningful unit tests for this problem.

kakyoism commented 3 years ago

It's interesting that I hit a similar case that's much easier to reproduce. So I'll post it here. Note that this is not exactly the same as what I saw regarding the pull request, but the faults are both related to create_connection

Setup

$ pip show waapi-client
Name: waapi-client
Version: 0.6
Summary: Wwise Authoring API client.
Home-page: https://github.com/audiokinetic/waapi-client-python
Author: Audiokinetic
Author-email: None
License: Apache License 2.0
Location: /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages
Requires: autobahn
Required-by: 

Repro

Step 1: Open headless waapi-server from Terminal

/Applications/Audiokinetic/Wwise_2021.1.1.7601/Wwise.app/Contents/Tools/WwiseConsole.sh waapi-server /path/to/wwise_proj/wwise_proj.wproj --allow-migration --wamp-port 8080

Step 2: Run the following in jupyter notebook

from waapi import WaapiClient, CannotConnectToWaapiException
import pprint as pp

print('start')
query = '"{99F3C8C5-03E1-47DD-9872-C9E36A797DD4}"'
url = 'ws://127.0.0.1:8080/waapi'
with WaapiClient(url=url) as client:
    result = client.call("ak.wwise.core.object.get", waql=query, options={'return': ['path', 'type', 'id']})
    pp.pprint(result)
print('done')

Expected

I should get a clean result without crashing.

Observation

start
None
done
RuntimeError('This event loop is already running')
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/waapi/wamp/ak_autobahn.py:179: RuntimeWarning: coroutine 'BaseEventLoop.create_connection' was never awaited
  self._decoupler.set_joined()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

Workaround

Run the same client code in a Terminal instance works as expected

start
{'return': [{'id': '{99F3C8C5-03E1-47DD-9872-C9E36A797DD4}',
             'path': '\\',
             'type': 'Project'}]}
done