-
Notifications
You must be signed in to change notification settings - Fork 732
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
import of paho.mqtt.client not possible when ONLY importing in subthread #882
Comments
Can you provide all package versions using |
absl-py==2.1.0 |
Thanks. I just cooked up a more basic version. Note that this must run as a script and not in a REPL. import threading
def run():
import concurrent.futures.thread
threading.Thread(target=run).start() There are no dependencies needed and thus it looks like a python issue. There might be other issues out there related to this. To trigger this as written in the issue, requires some packages like |
The exception give you the hints of the problem: You stopped the Python main thread (which I should be "after shutdown") Slightly extended version of last sample
You should wait for the thread:
|
Bug Description
When running a python script and trying to import paho.mqtt.client in a subthread, without first importing the library in the main thread, an exception occurs. If the library is imported before in the main thread, no problems occurr.
Reproduction
This simple code snippet:
executes up to the first print statement, I see the "Starting MQTT" message, then the following exception occurrs:
RuntimeError: can't register atexit after shutdown
When doing the same without the subthread, there are no problems at all. Also, when first importing the package in the main thread, like here:
also works just fine.
Environment
Whole Stacktrace:
Starting MQTT
Exception in thread Thread-1 (mqtt_thread):
Traceback (most recent call last):
File "C:\Python\311_x64\Lib\threading.py", line 1045, in _bootstrap_inner
self.run()
File "C:\Python\311_x64\Lib\threading.py", line 982, in run
self._target(*self._args, **self._kwargs)
File "c:\Users\KonstantinWaser\Desktop\pahotest.py", line 18, in mqtt_thread
import paho.mqtt.client as mqtt
File "C:\Python\311_x64\Lib\site-packages\paho\mqtt\client.py", line 116, in
import dns.resolver
File "C:\Python\311_x64\Lib\site-packages\dns\resolver.py", line 30, in
import dns._ddr
File "C:\Python\311_x64\Lib\site-packages\dns_ddr.py", line 12, in
import dns.nameserver
File "C:\Python\311_x64\Lib\site-packages\dns\nameserver.py", line 5, in
import dns.asyncquery
File "C:\Python\311_x64\Lib\site-packages\dns\asyncquery.py", line 38, in
from dns.query import (
File "C:\Python\311_x64\Lib\site-packages\dns\query.py", line 64, in
import httpcore.backends.sync
File "C:\Python\311_x64\Lib\site-packages\httpcore_init.py", line 1, in
from ._api import request, stream
File "C:\Python\311_x64\Lib\site-packages\httpcore_api.py", line 5, in
from .sync.connection_pool import ConnectionPool
File "C:\Python\311_x64\Lib\site-packages\httpcore_sync_init.py", line 1, in
from .connection import HTTPConnection
File "C:\Python\311_x64\Lib\site-packages\httpcore_sync\connection.py", line 12, in
from ..synchronization import Lock
File "C:\Python\311_x64\Lib\site-packages\httpcore_synchronization.py", line 16, in
import anyio
File "C:\Python\311_x64\Lib\site-packages\anyio_init.py", line 21, in
from ._core.fileio import AsyncFile as AsyncFile
File "C:\Python\311_x64\Lib\site-packages\anyio_core_fileio.py", line 21, in
from .. import to_thread
File "C:\Python\311_x64\Lib\site-packages\anyio\to_thread.py", line 9, in
from .abc import CapacityLimiter
File "C:\Python\311_x64\Lib\site-packages\anyio\abc_init.py", line 50, in
from ..from_thread import BlockingPortal as BlockingPortal
File "C:\Python\311_x64\Lib\site-packages\anyio\from_thread.py", line 6, in
from concurrent.futures import FIRST_COMPLETED, Future, ThreadPoolExecutor, wait
File "", line 1229, in handle_fromlist
File "C:\Python\311_x64\Lib\concurrent\futures_init.py", line 49, in getattr
from .thread import ThreadPoolExecutor as te
File "C:\Python\311_x64\Lib\concurrent\futures\thread.py", line 37, in
threading._register_atexit(_python_exit)
File "C:\Python\311_x64\Lib\threading.py", line 1527, in _register_atexit
raise RuntimeError("can't register atexit after shutdown")
RuntimeError: can't register atexit after shutdown
The text was updated successfully, but these errors were encountered: