pytoggle | Small utility for easily switching multiple | Natural Language Processing library
kandi X-RAY | pytoggle Summary
kandi X-RAY | pytoggle Summary
Small utility for easily switching multiple virtual environments and python installations
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of pytoggle
pytoggle Key Features
pytoggle Examples and Code Snippets
Community Discussions
Trending Discussions on pytoggle
QUESTION
I have some issues when toggle button is set to OFF it goes back to ON as json read still gets not refreshed value and kicks in slot_method. But I need this if statement to read initial value when launching the app and this mode allready can be selected from hardware controller. How it can be reworked that on toggle button click 1 json read thread could be excluded ?
py_toggle.py
...ANSWER
Answered 2022-Feb-25 at 00:16There are two problems in your implementation.
The first one is that the QThread actually runs the function in the separate thread just the first time (when start()
is called), while the QTimer
will always execute it in the main thread, where it was created. run()
should never be explicitly called.
Then, and this is the main point of your issue, the signal should always be emitted only when the value changes, not every time it is requested.
Finally, since requests are potentially blocking, the command sent from the UI should also be threaded. We already have a thread running, so we could use that along with a python Queue
.
There are also other issues:
- as the documentation explicitly says,
terminate()
is discouraged, as using it could cause problems and stability issues; using a simple flag is way more simple and safer; in any case, with your original code it wouldn't do nothing anyway, unless called as soon as the thread is started: as stated above, each further execution was done in the wrong thread, soterminate()
will do nothing useful; - the second
try
/except
block is pointless, as there is no possibility for that type of exception in there; the only exception that would make sense at that point is theKeyError
for the dictionary lookup; - the
stateChanged
signal is for tri-state checkboxes, for standard dual state the proper signal istoggled
;
A proper implementation must keep the thread running in a while
loop, and eventually quit when necessary. Using the queue timeout
argument we also get the 6 second interval, so there is no need for timers.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install pytoggle
You can use pytoggle like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page