Python Forum
Multiprocessing.Queue with hugh data causes _wait_for_tstate_lock
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiprocessing.Queue with hugh data causes _wait_for_tstate_lock
#1
X-Post on StackOverflow

An Exception is raised in threading._wait_for_tstate_lock when I transfere hugh data between a Process and a Thread via multiprocessing.Queue.

I have the vague idea that it has something to do with the fact that a multiprocessing Queue uses a internal Thread and a buffer. But I do not fully understand it.

This is the output and error message of my application
Output:
Running MyProcess... MyProcess stoppd. ^CProcess MyProcess-1: Exception ignored in: <module 'threading' from '/usr/lib/python3.5/threading.py'> Traceback (most recent call last): File "/usr/lib/python3.5/threading.py", line 1288, in _shutdown t.join() File "/usr/lib/python3.5/threading.py", line 1054, in join self._wait_for_tstate_lock() File "/usr/lib/python3.5/threading.py", line 1070, in _wait_for_tstate_lock elif lock.acquire(block, timeout): KeyboardInterrupt Traceback (most recent call last): File "/usr/lib/python3.5/multiprocessing/process.py", line 252, in _bootstrap util._exit_function() File "/usr/lib/python3.5/multiprocessing/util.py", line 314, in _exit_function _run_finalizers() File "/usr/lib/python3.5/multiprocessing/util.py", line 254, in _run_finalizers finalizer() File "/usr/lib/python3.5/multiprocessing/util.py", line 186, in __call__ res = self._callback(*self._args, **self._kwargs) File "/usr/lib/python3.5/multiprocessing/queues.py", line 198, in _finalize_join thread.join() File "/usr/lib/python3.5/threading.py", line 1054, in join self._wait_for_tstate_lock() File "/usr/lib/python3.5/threading.py", line 1070, in _wait_for_tstate_lock elif lock.acquire(block, timeout): KeyboardInterrupt
This is the example code
#!/usr/bin/env python3

import multiprocessing
import threading
import time
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import GLib


class MyThread (threading.Thread):
    """This thread just starts the process."""
    def __init__(self, callback):
        threading.Thread.__init__(self)
        self._callback = callback

    def run(self):
        print('Running MyThread...')
        self.result = []

        queue = multiprocessing.Queue()
        process = MyProcess(queue)
        process.start()
        process.join()

        while not queue.empty():
            process_result = queue.get()
            self.result.append(process_result)
        print('MyThread stoppd.')
        GLib.idle_add(self._callback)


class MyProcess (multiprocessing.Process):
    def __init__(self, queue):
        multiprocessing.Process.__init__(self)
        self.queue = queue

    def run(self):
        print('Running MyProcess...')
        for i in range(3):
            self.queue.put((i, 'x'*102048))
        print('MyProcess stoppd.')

class MyWindow (Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.connect('destroy', Gtk.main_quit)
        GLib.timeout_add(2000, self.do_start)

    def do_start(self):
        print('MyWindow::do_start()')
        # The process need to be started from a separate thread
        # to prevent the main thread (which is the gui main loop)
        # from freezing while waiting for the process result.
        self.thread = MyThread(self.callback_thread_finished)
        self.thread.start()

    def callback_thread_finished(self):
        result = self.thread.result
        for r in result:
            print('{} {}...'.format(r[0], r[1][:10]))

if __name__ == '__main__':
    win = MyWindow()
    win.show_all()
    Gtk.main()

The question was answered on StackOverflow: https://stackoverflow.com/a/56324244/4865723 .

I think I totally missunderstand the meaning of join.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Multiprocessing queue catch get timeout Pythocodras 1 2,323 Apr-22-2022, 06:01 PM
Last Post: Pythocodras
  Multiprocessing, class, run and a Queue Object SeanInColo 0 1,545 Jul-12-2020, 05:36 PM
Last Post: SeanInColo
  task queue Valon1981 8 3,605 Jul-07-2020, 07:41 AM
Last Post: freeman
  Queue in Pygame constantin01 1 3,686 Jan-07-2020, 04:02 PM
Last Post: metulburr
  Queue maxsize mr_byte31 2 4,555 Sep-03-2019, 07:02 PM
Last Post: mr_byte31
  Multiprocessing.Queue Issues (Missing/Corrupted Items/No Output) python3noob 0 3,209 Aug-03-2019, 09:38 PM
Last Post: python3noob
  multiprocessing.Queue.put(,,0) not documented Skaperen 2 2,042 Jul-30-2019, 09:01 AM
Last Post: perfringo
  multiprocessing.Queue.join_thread() says "thread" Skaperen 0 2,166 Jul-29-2019, 12:45 AM
Last Post: Skaperen
  Queue.Queue() would not reduce capacity after get() yuan8421 9 11,076 Jan-02-2018, 09:38 PM
Last Post: Windspar
  Threading and Queue nexusfactor 5 4,276 Oct-16-2017, 04:14 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020