| 1 |
Miscellaneous |
| 2 |
============= |
| 3 |
|
| 4 |
.. currentmodule:: websockets |
| 5 |
|
| 6 |
Why do I get the error: ``module 'websockets' has no attribute '...'``? |
| 7 |
....................................................................... |
| 8 |
|
| 9 |
Often, this is because you created a script called ``websockets.py`` in your |
| 10 |
current working directory. Then ``import websockets`` imports this module |
| 11 |
instead of the websockets library. |
| 12 |
|
| 13 |
.. _real-import-paths: |
| 14 |
|
| 15 |
Why is the default implementation located in ``websockets.legacy``? |
| 16 |
................................................................... |
| 17 |
|
| 18 |
This is an artifact of websockets' history. For its first eight years, only the |
| 19 |
:mod:`asyncio` implementation existed. Then, the Sans-I/O implementation was |
| 20 |
added. Moving the code in a ``legacy`` submodule eased this refactoring and |
| 21 |
optimized maintainability. |
| 22 |
|
| 23 |
All public APIs were kept at their original locations. ``websockets.legacy`` |
| 24 |
isn't a public API. It's only visible in the source code and in stack traces. |
| 25 |
There is no intent to deprecate this implementation — at least until a superior |
| 26 |
alternative exists. |
| 27 |
|
| 28 |
Why is websockets slower than another library in my benchmark? |
| 29 |
.............................................................. |
| 30 |
|
| 31 |
Not all libraries are as feature-complete as websockets. For a fair benchmark, |
| 32 |
you should disable features that the other library doesn't provide. Typically, |
| 33 |
you may need to disable: |
| 34 |
|
| 35 |
* Compression: set ``compression=None`` |
| 36 |
* Keepalive: set ``ping_interval=None`` |
| 37 |
* UTF-8 decoding: send ``bytes`` rather than ``str`` |
| 38 |
|
| 39 |
If websockets is still slower than another Python library, please file a bug. |
| 40 |
|
| 41 |
Are there ``onopen``, ``onmessage``, ``onerror``, and ``onclose`` callbacks? |
| 42 |
............................................................................ |
| 43 |
|
| 44 |
No, there aren't. |
| 45 |
|
| 46 |
websockets provides high-level, coroutine-based APIs. Compared to callbacks, |
| 47 |
coroutines make it easier to manage control flow in concurrent code. |
| 48 |
|
| 49 |
If you prefer callback-based APIs, you should use another library. |