Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3396372
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:23:59+00:00 2026-05-18T04:23:59+00:00

I have a thread which produces some data (a python list) and which shall

  • 0

I have a thread which produces some data (a python list) and which shall be available for a widget that will read and display the data in the main thread.
Actually, I’m using QMutex to provide access to the data, in this way:

class Thread(QThread):
  def get_data(self):
    QMutexLock(self.mutex)
    return deepcopy(self.data)

  def set_data(self, data):
    QMutexLock(self.mutex)
    self.data = deepcopy(data)

  def run(self):
    self.mutex = QMutex()
    while True:
      self.data = slowly_produce_data()
      self.emit(SIGNAL("dataReady()"))

class Widget(QWidget):
  def __init__(self):
    self.thread = Thread()
    self.connect(self.thread, SIGNAL("dataReady()"), self.get_data)
    self.thread.start()

  def get_data(self):
    self.data = self.thread.get_data()

  def paintEvent(self, event):
    paint_somehow(self.data)

Note that I’m not passing the data in the emit() as they are generic data (I tried to use PyObject as data type, but a double free() would crash the program), but I’m copying the data with a deepcopy() (assuming the data can be copied like this).
I used a deepcopy() because I guess that a code like:

def get_data(self):
  QMutexLock(self.mutex)
  return self.data

would only copy a reference to the data (right?) and data would be shared AND unlocked after the return…
Is this code correct?
What can I do if data are really large (like a list of 1’000’000 items)?

Thanks.

P.S. I saw some examples, like the Qt Mandelbrot example, or the threading example with PyQt, but they use QImage as parameter in the slots.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:24:00+00:00Added an answer on May 18, 2026 at 4:24 am

    I think this should work with PySide. if not work please report a bug on PySide bugzilla(http://bugs.openbossa.org/) with a small test case:

    class Thread(QThread):
      dataReady = Signal(object)
    
      def run(self):
        while True:
          self.data = slowly_produce_data()
          # this will add a ref to self.data and avoid the destruction 
          self.dataReady.emit(self.data) 
    
    class Widget(QWidget):
      def __init__(self):
        self.thread = Thread()
        self.thread.dataReady.connect(self.get_data, Qt.QueuedConnection)
        self.thread.start()
    
      def get_data(self, data):
        self.data = data
    
      def paintEvent(self, event):
        paint_somehow(self.data)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one std::list<> container and these threads: One writer thread which adds elements
In my C# program, I have a thread that represents a running test, which
I have a layered application in Java which has a multi thread data access
I have a Python program that runs a series of experiments, with no data
I have thread exception handler which saves the exception stack trace and should close
I'm working on a thread library which implement user level threads (i have something
I have a class which is not thread safe: class Foo { /* Abstract
I have one thread that writes results into a Queue. In another thread (GUI),
I have some thread-related questions, assuming the following code. Please ignore the possible inefficiency
We have some code on production which is effectively doing what this code does:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.