You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I added pubnub.publish to the main function in examples/pubnub_asyncio_simple/main.py. After that, pressing Ctrl+C results in the following error output (ReadError). What could be the issue?
Python 3.13
importasyncioimportosfrompubnub.enumsimportPNStatusCategoryfrompubnub.pnconfigurationimportPNConfigurationfrompubnub.pubnub_asyncioimportPubNubAsyncio, SubscribeCallbackclassMySubscribeCallback(SubscribeCallback):
defstatus(self, pubnub, status):
ifstatus.category==PNStatusCategory.PNUnexpectedDisconnectCategory:
print("Disconnected")
elifstatus.category==PNStatusCategory.PNConnectedCategory:
print("Connected")
elifstatus.category==PNStatusCategory.PNReconnectedCategory:
print("Reconnected")
elifstatus.category==PNStatusCategory.PNDecryptionErrorCategory:
print("Decryption error")
defmessage(self, pubnub, message):
print(f"Received message: {message.message} on channel: {message.channel}")
defpresence(self, pubnub, presence):
print(f"Presence event: {presence.event}")
asyncdefmain(pubnub):
pubnub.subscribe().channels("my_channel").execute()
# Addedawaitasyncio.sleep(1)
awaitpubnub.publish(
channel="my_channel", message="Hello from PubNub Python SDK"
).future()
print("Listening for messages...")
whileTrue:
awaitasyncio.sleep(1)
if__name__=="__main__":
loop=asyncio.new_event_loop()
asyncio.set_event_loop(loop)
pnconfig=PNConfiguration()
pnconfig.subscribe_key=os.getenv("PUBNUB_SUBSCRIBE_KEY") or"demo"pnconfig.publish_key=os.getenv("PUBNUB_PUBLISH_KEY") or"demo"pnconfig.user_id="my_unique_user_id"# Set a unique user IDpubnub=PubNubAsyncio(pnconfig)
callback=MySubscribeCallback()
pubnub.add_listener(callback)
try:
loop.run_until_complete(main(pubnub))
exceptKeyboardInterrupt:
print("Interrupted by user. Exiting...")
finally:
loop.run_until_complete(pubnub.stop()) # Assuming 'pubnub' is in scopeloop.close()
ConnectedListening for messages...Received message: Hello from PubNub Python SDK on channel: my_channel^CInterrupted by user. Exiting...session.request exception: Recieve messages failed: {'information': '', 'exception': ReadError('')}EventEngine is not enabled
The text was updated successfully, but these errors were encountered:
Is it possible to properly terminate the HTTPX network on the application side? I suspect that there might be an issue with the AsyncHttpxRequestHandler in the library or improper shutdown of the event loop.
I am in process of improving the error handlers so there should be some benefits soon. But from I already found the process seems to be cleaning up pretty decently
I added
pubnub.publish
to themain
function inexamples/pubnub_asyncio_simple/main.py
. After that, pressing Ctrl+C results in the following error output (ReadError
). What could be the issue?Python 3.13
The text was updated successfully, but these errors were encountered: