-
-
Notifications
You must be signed in to change notification settings - Fork 527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to pass additional args to server function in Basic example file? #271
Comments
I'm going off memory, but I'm pretty sure you can accomplish the same end goal by subclassing |
Does this work? import functools
start_server = websockets.serve(
functools.partial(hello, parent_conn=parent_conn),
'127.0.0.1', 8765) |
to aaugustin:
Can you add this to the getting started section? It was one of the first questions I had and I went through all of the closed "issues" looking for clues about this. |
Nope. It does matter where I put the argument. Putting it ahead of websocket or even in between give me this error.
|
I don't think this is hello-world material, however it's worth adding to the docs. |
Looks like these docs added in 050a6ae eventually got removed in latest somehow. Also there's an issue with them. The path argument was deprecated and some magic was added here: https://github.com/aaugustin/websockets/blob/668f320/src/websockets/legacy/server.py#L1123 When attempting to use a functools.partial with a simple 2 argument handler such as
It will pass through that block and generate errors such as The workaround for now is to avoid getting caught by that deprecation block which checks if your functions expects 2 arguments, by simply adding a third dummy argument
Maybe @aaugustin should reconsider the deprecation here for cases like this? |
I think this is the same as #1095. |
I must be missing something simple here. I'm looking at the Basic server and client examples in the docs but it's not clear to me how to pass additional arguments to the 'hello' function. Here's a piece of code where I want to pass a multiprocessing pipe endpoint to the function. It doesn't work but I think illustrates what I'm trying to do.
The text was updated successfully, but these errors were encountered: