-
Notifications
You must be signed in to change notification settings - Fork 3
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
port introduction snippets to use async def
and t.i.t.react
#20
Comments
I don't know what is the scope of this issue, but it shouldn't be blocked. The from page is just a simple HTML page with the content here https://github.com/twisted/twisted.github.io/blob/main/index.html |
I'm worried if I add more HTML it will make it harder to switch to rst |
so this code: from twisted.internet import protocol, reactor, endpoints
class Echo(protocol.Protocol):
def dataReceived(self, data):
self.transport.write(data)
class EchoFactory(protocol.Factory):
def buildProtocol(self, addr):
return Echo()
endpoints.serverFromString(reactor, "tcp:1234").listen(EchoFactory())
reactor.run() becomes: import math
from twisted.internet import protocol, endpoints, task
class Echo(protocol.Protocol):
def dataReceived(self, data):
self.transport.write(data)
class EchoFactory(protocol.Factory):
def buildProtocol(self, addr):
return Echo()
async def echo_server(reactor):
await endpoints.serverFromString(reactor, "tcp:1234").listen(EchoFactory())
await task.deferLater(reactor, math.inf, lambda: pass)
return 0
def main():
return task.react(echo_server)
if __name__ == "__main__":
sys.exit(main()) |
OK. I have created a PR. we can discuss the new changes there. I have no idea how a good example should look like... Should it contain comments... or the code should be simple enough so that the comments are not needed. Should it contain "hacks" . To me, the line below looks like a hack :)
The result is here https://deploy-preview-21--twisted-pr-preview.netlify.app/ |
Would be nice if you could just do async with server(port=0) as server:
print (f"listening on port {server.port}, waiting for ctrl+c")
await sleep_forever() Eh? |
:) This is very nice and I think a big selling point for new users. In real life, not having a context manager is not a big deal for me. I have created the PR, just to move things forward. Feel free to suggest whatever you think is best and we can request feedback from others. Thanks |
Feel free to add as much HTML as you want, I don't think it would impact the switch to RST at all :) |
No description provided.
The text was updated successfully, but these errors were encountered: