Debian Codegraph @

docs/faq/misc.rst

raw
1 Miscellaneous
2 =============
3
4 .. currentmodule:: websockets
5
6 .. Remove this question when dropping Python < 3.13, which provides natively
7 .. a good error message in this case.
8
9 Why do I get the error: ``module 'websockets' has no attribute '...'``?
10 .......................................................................
11
12 Often, this is because you created a script called ``websockets.py`` in your
13 current working directory. Then ``import websockets`` imports this module
14 instead of the websockets library.
15
16 Why is websockets slower than another library in my benchmark?
17 ..............................................................
18
19 Not all libraries are as feature-complete as websockets. For a fair benchmark,
20 you should disable features that the other library doesn't provide. Typically,
21 you must disable:
22
23 * Compression: set ``compression=None``
24 * Keepalive: set ``ping_interval=None``
25 * Limits: set ``max_size=None``
26 * UTF-8 decoding: send ``bytes`` rather than ``str``
27
28 Then, please consider whether websockets is the bottleneck of the performance
29 of your application. Usually, in real-world applications, CPU time spent in
30 websockets is negligible compared to time spent in the application logic.
31
32 Are there ``onopen``, ``onmessage``, ``onerror``, and ``onclose`` callbacks?
33 ............................................................................
34
35 No, there aren't.
36
37 websockets provides high-level, coroutine-based APIs. Compared to callbacks,
38 coroutines make it easier to manage control flow in concurrent code.
39
40 If you prefer callback-based APIs, you should use another library.