[issue42445] Assertion in run_coroutine_threadsafe

2020-11-24 Thread Jochen Kienzle


Jochen Kienzle  added the comment:

Thanks for your reply.

I already tried 


asyncio.run(self.mqtt_client.publish_json(INGESTION_TOPIC, msg))


but this leads (rarely) to the following error:


got Future  attached to a different loop


I want to point out that asyncio.run() was called in a thread without an event 
loop.

So, it seems to be that the issue is either on asyncio or on hbmqtt.client side 
(loop handling).

Any opinions, ideas or hints?

--

___
Python tracker 
<https://bugs.python.org/issue42445>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42445] Assertion in run_coroutine_threadsafe

2020-11-23 Thread Jochen Kienzle


New submission from Jochen Kienzle :

Hello,

in my implementation I want to call mqtt_client.publish_json from a sync method:

-
def __on_event(self, ev):
...

asyncio.run_coroutine_threadsafe(self.mqtt_client.publish_json(INGESTION_TOPIC, 
msg), loop=self.publish_loop)
-

where self.broker.publish_json is an async function and publish_loop is a loop 
which has been started (run_forever) in a separate thread:

---
self.publish_loop = asyncio.new_event_loop()
t = threading.Thread(target=self.publish_loop.run_forever)
t.start()
---

Sometimes (about 1 in 400 calls) I get the following Assertion Error:

-
?[94;1m== APP == Exception in callback 
_ProactorBaseWritePipeTransport._loop_writing(<_OverlappedF...ed result=366>)
?[0m
?[94;1m== APP == handle: )>
[0m
[94;1m== APP == Traceback (most recent call last):
[0m
[94;1m== APP ==   File 
"C:\Users\sio7fe\AppData\Local\Programs\Python\Python38-32\lib\asyncio\events.py",
 line 81, in _run
[0m
[94;1m== APP == self._context.run(self._callback, *self._args)
[0m
[94;1m== APP ==   File 
"C:\Users\sio7fe\AppData\Local\Programs\Python\Python38-32\lib\asyncio\proactor_events.py",
 line 375, in _loop_writing
[0m
[94;1m== APP == assert f is self._write_fut
[0m
[94;1m== APP == AssertionError
-

Run time behavior:
 - publish_loop will be re-used on each event
 - run_coroutine_threadsafe will be called multiple times without any sleep 
(its in a for-loop with 1-3 elements)


Since this is a thread safe method and its working multiple times, it seems to 
be some run-time related issue and I can't figure out the root cause.

--
components: asyncio
messages: 381674
nosy: JoKi, asvetlov, yselivanov
priority: normal
severity: normal
status: open
title: Assertion in run_coroutine_threadsafe
type: behavior
versions: Python 3.8

___
Python tracker 
<https://bugs.python.org/issue42445>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com