Skip to content

Simulating Multiple Servers #1272

Answered by AndreasHeine
JiaNannnn asked this question in Q&A
Discussion options

You must be logged in to vote

each Server needs to be in a own asyncio task!

e.g.:

async def server1():
    # create the server here
    pass

async def server2():
    # create the server here
    pass

async def main():
    task1 = asyncio.create_task(server1())
    task2 = asyncio.create_task(server2())
    await asyncio.gather(task1, task2)

if __name__ == "__main__":
    # since python 3.8 has changed the default event loop
    # only if your on windows
    if sys.platform.lower() == "win32" or os.name.lower() == "nt":
        from asyncio import (
            set_event_loop_policy,
            WindowsSelectorEventLoopPolicy
        )
        set_event_loop_policy(WindowsSelectorEventLoopPolicy())
    asyncio.run(m…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@JiaNannnn
Comment options

Comment options

You must be logged in to vote
1 reply
@JiaNannnn
Comment options

Answer selected by JiaNannnn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants