Skip to content

Blocking client cannot send to Async client #1

@ajoino

Description

@ajoino

This is on IPyC version 1.1.1

I'm using this lib for a research project, and I find it very nice to work with.
However, I'm having trouble sending messages between an AsyncIPyCHost and an IPyCClient.

I have a minimum working example:

# Host (Async):
import asyncio

import ipyc


host = ipyc.AsyncIPyCHost()
@host.on_connect
async def connection(link: ipyc.AsyncIPyCLink):
    print("Connection established!")
    while link.is_active():
        message = await link.receive()
        await link.send(f"Thank you for the {message}")

if __name__ == "__main__":
    host.run()
# Client (Blocking):
import ipyc

client = ipyc.IPyCClient()
link = client.connect()
link.send("cheese")
print(link.receive())
link.close()

If you run the host script and the then client script, the host prints "Connection established!" and the client hangs.
An equivalent AsyncIPyCClient:

# Client (Async):
import asyncio

import ipyc

async def main():
    client = ipyc.AsyncIPyCClient()
    link = await client.connect()

    await link.send("cheese")
    print(await link.receive())

if __name__ == "__main__":
    asyncio.run(main())

Will run and print "Thank you for the cheese!", but it will freeze when trying to send a message to an IPyCHost:

# Host (Blocking)
import ipyc

host = ipyc.IPyCHost()

while not host.is_closed():
    connection = host.wait_for_client()

    print("Connection established")
    while connection.is_active():
        message = connection.receive()
        connection.send(f"Thank you for the block of {message}!")

With the following traceback if I interrupt the async client when it freezes:

^CTraceback (most recent call last):
  File "ipyc_async_client_test.py", line 13, in <module>
    asyncio.run(main())
  File "/home/jacnil/anaconda3/lib/python3.7/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "/home/jacnil/anaconda3/lib/python3.7/asyncio/base_events.py", line 570, in run_until_complete
    self.run_forever()
  File "/home/jacnil/anaconda3/lib/python3.7/asyncio/base_events.py", line 538, in run_forever
    self._run_once()
  File "/home/jacnil/anaconda3/lib/python3.7/asyncio/base_events.py", line 1746, in _run_once
    event_list = self._selector.select(timeout)
  File "/home/jacnil/anaconda3/lib/python3.7/selectors.py", line 468, in select
    fd_event_list = self._selector.poll(timeout, max_ev)
KeyboardInterrupt

But your examples work which confuses me to no end. In fact, your mixed hello world ipyc client script works with my async host. Do you know what I'm doing wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions