question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with threads

See original GitHub issue

Hi, thanks a bunch for your effort with this project! I have modified camera_class.py to read frames from a mjpeg stream instead of a raspi cam. Everything seems to be working just fine (detecting cats etc.) up until a thread is supposed to be started to send a message to the telegram bot, then I get this:

NO CAT FOUND!
CLEARED QUEQUE BECAUSE EVENT OVER WITHOUT CONCLUSION...
CatCamPy: C:\Users\englund\Documents\GitHub
Traceback (most recent call last):
  File ".\cascade.py", line 743, in <module>
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    sq_cascade.queque_handler()
  File ".\cascade.py", line 341, in queque_handler
  File "C:\Users\englund\AppData\Local\Programs\Python\Python38\lib\multiprocessing\spawn.py", line 116, in spawn_main
    exitcode = _main(fd, parent_sentinel)
    self.queque_worker()
  File "C:\Users\englund\AppData\Local\Programs\Python\Python38\lib\multiprocessing\spawn.py", line 126, in _main
  File ".\cascade.py", line 303, in queque_worker
    self = reduction.pickle.load(from_parent)
EOFError: Ran out of input
    p.start()
  File "C:\Users\englund\AppData\Local\Programs\Python\Python38\lib\multiprocessing\process.py", line 121, in start
    self._popen = self._Popen(self)
  File "C:\Users\englund\AppData\Local\Programs\Python\Python38\lib\multiprocessing\context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "C:\Users\englund\AppData\Local\Programs\Python\Python38\lib\multiprocessing\context.py", line 327, in _Popen
    return Popen(process_obj)
  File "C:\Users\englund\AppData\Local\Programs\Python\Python38\lib\multiprocessing\popen_spawn_win32.py", line 93, in __init__
    reduction.dump(process_obj, to_child)
  File "C:\Users\englund\AppData\Local\Programs\Python\Python38\lib\multiprocessing\reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
TypeError: cannot pickle '_thread.RLock' object

Any thoughts on why this is happening and how to fix it would be very appreciated!

The new camera class looks like this:

class Camera:
    def __init__(self,):
        time.sleep(2)

    def fill_queue(self, deque):
        while(1):
            gc.collect()
            i = 0
            stream = urllib.request.urlopen('http://localhost:8000/camera/mjpeg')
            bytes = b''
            while True:
                bytes += stream.read(1024)
                a = bytes.find(b'\xff\xd8') # JPEG start
                b = bytes.find(b'\xff\xd9') # JPEG end
                if a!=-1 and b!=-1:
                    jpg = bytes[a:b+2] # actual image
                    bytes= bytes[b+2:] # other informations
                    image = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8),cv2.IMREAD_COLOR) 
                    deque.append(
                        (datetime.now(pytz.timezone('Europe/Zurich')).strftime("%Y_%m_%d_%H-%M-%S.%f"), image))
                    #deque.pop()
                    print("Quelength: " + str(len(deque)) + "\tStreamsize: " + str(sys.getsizeof(stream)))
                    i += 1

                if i == 60:
                    print("Loop ended, starting over.")
                    stream.close()
                    break

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
larsenglundcommented, Oct 28, 2020

Removing old images from the queue made everything work! Thanks for your help! image Now I can proceed to make the actual hardware installation, looking forward to not being woken up at 3 by the cats playing with prey under the bed >_<

1reaction
larsenglundcommented, Oct 28, 2020

Thanks for the quick reply! I’ll start by spinning up a virtual machine with linux then to eliminate that possible error source!

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Problem with Threads - Berkeley EECS
Abstract. Threads are a seemingly straightforward adaptation of the dominant sequential model of computation to concurrent systems.
Read more >
The Problem with Threads - IEEE Computer Society
From a fundamental perspective, threads are seriously flawed as a computation model because they are wildly nondeterministic, as the " Nondeterminism and ...
Read more >
The problem with threads | IEEE Journals & Magazine
The problem with threads. Abstract: For concurrent programming to become mainstream, we must discard threads as a programming model.
Read more >
Common Problems and Pitfalls with Multi-Thread Programming
The Main Problems in Multi-Threaded Programming​​ However, in reality, the threads and processes of a parallel program compete for the limited ...
Read more >
(PDF) The Problem with Threads - ResearchGate
For concurrent programming to become mainstream, we must discard threads as a programming model. Nondeterminism should be judiciously and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found