-
Notifications
You must be signed in to change notification settings - Fork 81
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
thread handler: don't start multiple thread instances #1809
Conversation
def thread_handler(thread: threading.Thread): | ||
if is_thread_alive(thread.name): | ||
log.error(f"Thread {thread.name} ist bereits aktiv und wird nicht erneut gestartet.") | ||
else: | ||
thread.start() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In z.B. phase_switch.py
wird nach dem Aufruf des thread_handler()
immer eine Erfolgsmeldung in das Log geschrieben. Das ist unabhängig davon, ob der neue Thread wirklich gestartet wurde. Es wäre sinnvoll, wenn thread_handler()
einen Status zurückgeben würde, um solche "Falschmeldungen" abzufangen.
def thread_handler(thread: threading.Thread): | |
if is_thread_alive(thread.name): | |
log.error(f"Thread {thread.name} ist bereits aktiv und wird nicht erneut gestartet.") | |
else: | |
thread.start() | |
def thread_handler(thread: threading.Thread) -> bool: | |
if is_thread_alive(thread.name): | |
log.error(f"Thread {thread.name} ist bereits aktiv und wird nicht erneut gestartet.") | |
return False | |
else: | |
thread.start() | |
return True |
packages/control/phase_switch.py
Outdated
thread_handler(threading.Thread( | ||
target=_perform_phase_switch, | ||
args=(cp.chargepoint_module, | ||
cp.data.control_parameter.phases, | ||
cp.data.set.charging_ev_data, | ||
cp.data.get.charge_state), | ||
name=f"phase switch cp{cp.chargepoint_module.config.id}")) | ||
log.debug("Thread zur Phasenumschaltung an LP"+str(cp.num)+" gestartet.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Falls der Vorschlag zur Anpassung des htread_handler()
umgesetzt wird:
thread_handler(threading.Thread( | |
target=_perform_phase_switch, | |
args=(cp.chargepoint_module, | |
cp.data.control_parameter.phases, | |
cp.data.set.charging_ev_data, | |
cp.data.get.charge_state), | |
name=f"phase switch cp{cp.chargepoint_module.config.id}")) | |
log.debug("Thread zur Phasenumschaltung an LP"+str(cp.num)+" gestartet.") | |
if thread_handler(threading.Thread( | |
target=_perform_phase_switch, | |
args=(cp.chargepoint_module, | |
cp.data.control_parameter.phases, | |
cp.data.set.charging_ev_data, | |
cp.data.get.charge_state), | |
name=f"phase switch cp{cp.chargepoint_module.config.id}") | |
): | |
log.debug("Thread zur Phasenumschaltung an LP"+str(cp.num)+" gestartet.") |
f2d1b92
to
4111f1b
Compare
Vor dem Starten eines Threads wird geprüft, ob nicht bereits ein Thread mit gleichem Namen (der Name ist bei jedem Aufruf gleich) existiert. Dann wird kein weiterer Thread gestartet.