Skip to content
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

What is the point of the threading? #1

Open
fake-name opened this issue Jul 26, 2017 · 0 comments
Open

What is the point of the threading? #1

fake-name opened this issue Jul 26, 2017 · 0 comments

Comments

@fake-name
Copy link
Contributor

fake-name commented Jul 26, 2017

In https://github.com/raffmont/pynextion/blob/master/pynextion/__init__.py


    def nxRead(self, cmax=0, timeout=0):
        s = []
        done = False

        def _reader():
            count = 0
            time_now = time.clock()
            while timeout == 0 or (time.clock() - time_now) < timeout:
                r = self.ser.read()
                if r is None or r == "":
                    continue

                c = ord(r)
                if c == 0xff and len(s) == 0:
                    continue

                if c != 0x00:
                    if self.debug is True:
                        print("\/ :" + str(c) + ":" + str(len(s)) + ":" +
                              str(count))

                    s.append(c)
                    if len(s) == cmax:
                        return
                    if c == 0xff:
                        count = count + 1
                        if count == 3:
                            if self.debug is True:
                                print("!!")
                            return
                    else:
                        count = 0
                    if self.debug is True:
                        print("/\ :" + str(c) + ":" + str(len(s)) + ":" +
                              str(count))
            print("Timeout")

        t = Thread(target=_reader)
        t.start()
        t.join()
        return s

You're starting a separate thread to read from the com port, and then blocking until it completes.

Why is it even there? It's literally equivalent to just calling _reader() in the context of the main thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant