prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  import pyqtgraph.canvas fails.
  <!-- In the following, please describe your issue in detail! -->
  <!-- If some sections do not apply, just remove them. -->
  
  ### Short description
  Importing pyqtgraph.canvas causes the program to abort and exit with an error code..
  
  ### Code to reproduce
  <!-- Please provide a minimal working example that reproduces the issue in the code block below.
       Ideally, this should be a full example someone else could run without additional setup. -->
  
  ```python
  print("Mark 0", flush=True)
  import time
  print("Mark 1", flush=True)
  import pyqtgraph.canvas
  print("Mark 2", flush=True)
  time.sleep(10)
  print("Mark 3", flush=True)
  
  ```
  
  ### Expected behavior
  1. The program should print out all the markers four ,0 to 3, with a 10 seconds delay between marker 2 and 3.
  2. The program should exit with status code 0 (ok)
  
  
  ### Real behavior
  1. The program prints only markers 0 and 1.
  2. The program exist with status code 127 (error)
  
  ### An error occurred?
  No error messages were noticed. The program just exits when it tries to import pyqtgraph.canvas.
  
  ### Tested environment(s)
  
   * PyQtGraph version: <!-- output of pyqtgraph.__version__ --> 0.13.3
   * Qt Python binding: <!-- output of pyqtgraph.Qt.VERSION_INFO -->  PyQt6 6.5.2 Qt 6.5.2
   * Python version:  3.12.0
   * NumPy version: <!-- output of numpy.__version__ --> 1.26.0
   * Operating system:  Windows 10, Ryzen
   * Installation method: <!-- e.g. pip, conda, system packages, ... --> pip
  
  ### Additional context
  
  The issue is discussed here in the pyinstaller repository https://github.com/pyinstaller/pyinstaller/issues/7991#issuecomment-1752032919
  
  Swapping the two lines of CanvasManager as described the link above seems to fix the problem.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `pyqtgraph/canvas/CanvasManager.py`
  Content:
  ```
  1 from ..Qt import QtCore, QtWidgets
  2 
  3 if not hasattr(QtCore, 'Signal'):
  4     QtCore.Signal = QtCore.pyqtSignal
  5 import weakref
  6 
  7 
  8 class CanvasManager(QtCore.QObject):
  9     SINGLETON = None
  10     
  11     sigCanvasListChanged = QtCore.Signal()
  12     
  13     def __init__(self):
  14         if CanvasManager.SINGLETON is not None:
  15             raise Exception("Can only create one canvas manager.")
  16         CanvasManager.SINGLETON = self
  17         QtCore.QObject.__init__(self)
  18         self.canvases = weakref.WeakValueDictionary()
  19 
  20     @classmethod
  21     def instance(cls):
  22         return CanvasManager.SINGLETON
  23         
  24     def registerCanvas(self, canvas, name):
  25         n2 = name
  26         i = 0
  27         while n2 in self.canvases:
  28             n2 = "%s_%03d" % (name, i)
  29             i += 1
  30         self.canvases[n2] = canvas
  31         self.sigCanvasListChanged.emit()
  32         return n2
  33         
  34     def unregisterCanvas(self, name):
  35         c = self.canvases[name]
  36         del self.canvases[name]
  37         self.sigCanvasListChanged.emit()
  38         
  39     def listCanvases(self):
  40         return list(self.canvases.keys())
  41         
  42     def getCanvas(self, name):
  43         return self.canvases[name]
  44         
  45     
  46 manager = CanvasManager()
  47 
  48 
  49 class CanvasCombo(QtWidgets.QComboBox):
  50     def __init__(self, parent=None):
  51         QtWidgets.QComboBox.__init__(self, parent)
  52         man = CanvasManager.instance()
  53         man.sigCanvasListChanged.connect(self.updateCanvasList)
  54         self.hostName = None
  55         self.updateCanvasList()
  56         
  57     def updateCanvasList(self):
  58         canvases = CanvasManager.instance().listCanvases()
  59         canvases.insert(0, "")
  60         if self.hostName in canvases:
  61             canvases.remove(self.hostName)
  62             
  63         sel = self.currentText()
  64         if sel in canvases:
  65             self.blockSignals(True)  ## change does not affect current selection; block signals during update
  66         self.clear()
  67         for i in canvases:
  68             self.addItem(i)
  69             if i == sel:
  70                 self.setCurrentIndex(self.count())
  71             
  72         self.blockSignals(False)
  73         
  74     def setHostName(self, name):
  75         self.hostName = name
  76         self.updateCanvasList()
  77
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/pyqtgraph/canvas/CanvasManager.py b/pyqtgraph/canvas/CanvasManager.py
  --- a/pyqtgraph/canvas/CanvasManager.py
  +++ b/pyqtgraph/canvas/CanvasManager.py
  @@ -13,8 +13,9 @@
       def __init__(self):
           if CanvasManager.SINGLETON is not None:
               raise Exception("Can only create one canvas manager.")
  -        CanvasManager.SINGLETON = self
  +        # It is important to save SINGLETON *after* the call to QObject.__init__, see #2838.
           QtCore.QObject.__init__(self)
  +        CanvasManager.SINGLETON = self
           self.canvases = weakref.WeakValueDictionary()
   
       @classmethod
  
verification_info: {"golden_diff": "diff --git a/pyqtgraph/canvas/CanvasManager.py b/pyqtgraph/canvas/CanvasManager.py\n--- a/pyqtgraph/canvas/CanvasManager.py\n+++ b/pyqtgraph/canvas/CanvasManager.py\n@@ -13,8 +13,9 @@\n     def __init__(self):\n         if CanvasManager.SINGLETON is not None:\n             raise Exception(\"Can only create one canvas manager.\")\n-        CanvasManager.SINGLETON = self\n+        # It is important to save SINGLETON *after* the call to QObject.__init__, see #2838.\n         QtCore.QObject.__init__(self)\n+        CanvasManager.SINGLETON = self\n         self.canvases = weakref.WeakValueDictionary()\n \n     @classmethod\n", "issue": "import pyqtgraph.canvas fails.\n<!-- In the following, please describe your issue in detail! -->\r\n<!-- If some sections do not apply, just remove them. -->\r\n\r\n### Short description\r\nImporting pyqtgraph.canvas causes the program to abort and exit with an error code..\r\n\r\n### Code to reproduce\r\n<!-- Please provide a minimal working example that reproduces the issue in the code block below.\r\n     Ideally, this should be a full example someone else could run without additional setup. -->\r\n\r\n```python\r\nprint(\"Mark 0\", flush=True)\r\nimport time\r\nprint(\"Mark 1\", flush=True)\r\nimport pyqtgraph.canvas\r\nprint(\"Mark 2\", flush=True)\r\ntime.sleep(10)\r\nprint(\"Mark 3\", flush=True)\r\n\r\n```\r\n\r\n### Expected behavior\r\n1. The program should print out all the markers four ,0 to 3, with a 10 seconds delay between marker 2 and 3.\r\n2. The program should exit with status code 0 (ok)\r\n\r\n\r\n### Real behavior\r\n1. The program prints only markers 0 and 1.\r\n2. The program exist with status code 127 (error)\r\n\r\n### An error occurred?\r\nNo error messages were noticed. The program just exits when it tries to import pyqtgraph.canvas.\r\n\r\n### Tested environment(s)\r\n\r\n * PyQtGraph version: <!-- output of pyqtgraph.__version__ --> 0.13.3\r\n * Qt Python binding: <!-- output of pyqtgraph.Qt.VERSION_INFO -->  PyQt6 6.5.2 Qt 6.5.2\r\n * Python version:  3.12.0\r\n * NumPy version: <!-- output of numpy.__version__ --> 1.26.0\r\n * Operating system:  Windows 10, Ryzen\r\n * Installation method: <!-- e.g. pip, conda, system packages, ... --> pip\r\n\r\n### Additional context\r\n\r\nThe issue is discussed here in the pyinstaller repository https://github.com/pyinstaller/pyinstaller/issues/7991#issuecomment-1752032919\r\n\r\nSwapping the two lines of CanvasManager as described the link above seems to fix the problem.\r\n\n", "before_files": [{"content": "from ..Qt import QtCore, QtWidgets\n\nif not hasattr(QtCore, 'Signal'):\n    QtCore.Signal = QtCore.pyqtSignal\nimport weakref\n\n\nclass CanvasManager(QtCore.QObject):\n    SINGLETON = None\n    \n    sigCanvasListChanged = QtCore.Signal()\n    \n    def __init__(self):\n        if CanvasManager.SINGLETON is not None:\n            raise Exception(\"Can only create one canvas manager.\")\n        CanvasManager.SINGLETON = self\n        QtCore.QObject.__init__(self)\n        self.canvases = weakref.WeakValueDictionary()\n\n    @classmethod\n    def instance(cls):\n        return CanvasManager.SINGLETON\n        \n    def registerCanvas(self, canvas, name):\n        n2 = name\n        i = 0\n        while n2 in self.canvases:\n            n2 = \"%s_%03d\" % (name, i)\n            i += 1\n        self.canvases[n2] = canvas\n        self.sigCanvasListChanged.emit()\n        return n2\n        \n    def unregisterCanvas(self, name):\n        c = self.canvases[name]\n        del self.canvases[name]\n        self.sigCanvasListChanged.emit()\n        \n    def listCanvases(self):\n        return list(self.canvases.keys())\n        \n    def getCanvas(self, name):\n        return self.canvases[name]\n        \n    \nmanager = CanvasManager()\n\n\nclass CanvasCombo(QtWidgets.QComboBox):\n    def __init__(self, parent=None):\n        QtWidgets.QComboBox.__init__(self, parent)\n        man = CanvasManager.instance()\n        man.sigCanvasListChanged.connect(self.updateCanvasList)\n        self.hostName = None\n        self.updateCanvasList()\n        \n    def updateCanvasList(self):\n        canvases = CanvasManager.instance().listCanvases()\n        canvases.insert(0, \"\")\n        if self.hostName in canvases:\n            canvases.remove(self.hostName)\n            \n        sel = self.currentText()\n        if sel in canvases:\n            self.blockSignals(True)  ## change does not affect current selection; block signals during update\n        self.clear()\n        for i in canvases:\n            self.addItem(i)\n            if i == sel:\n                self.setCurrentIndex(self.count())\n            \n        self.blockSignals(False)\n        \n    def setHostName(self, name):\n        self.hostName = name\n        self.updateCanvasList()\n", "path": "pyqtgraph/canvas/CanvasManager.py"}], "after_files": [{"content": "from ..Qt import QtCore, QtWidgets\n\nif not hasattr(QtCore, 'Signal'):\n    QtCore.Signal = QtCore.pyqtSignal\nimport weakref\n\n\nclass CanvasManager(QtCore.QObject):\n    SINGLETON = None\n    \n    sigCanvasListChanged = QtCore.Signal()\n    \n    def __init__(self):\n        if CanvasManager.SINGLETON is not None:\n            raise Exception(\"Can only create one canvas manager.\")\n        # It is important to save SINGLETON *after* the call to QObject.__init__, see #2838.\n        QtCore.QObject.__init__(self)\n        CanvasManager.SINGLETON = self\n        self.canvases = weakref.WeakValueDictionary()\n\n    @classmethod\n    def instance(cls):\n        return CanvasManager.SINGLETON\n        \n    def registerCanvas(self, canvas, name):\n        n2 = name\n        i = 0\n        while n2 in self.canvases:\n            n2 = \"%s_%03d\" % (name, i)\n            i += 1\n        self.canvases[n2] = canvas\n        self.sigCanvasListChanged.emit()\n        return n2\n        \n    def unregisterCanvas(self, name):\n        c = self.canvases[name]\n        del self.canvases[name]\n        self.sigCanvasListChanged.emit()\n        \n    def listCanvases(self):\n        return list(self.canvases.keys())\n        \n    def getCanvas(self, name):\n        return self.canvases[name]\n        \n    \nmanager = CanvasManager()\n\n\nclass CanvasCombo(QtWidgets.QComboBox):\n    def __init__(self, parent=None):\n        QtWidgets.QComboBox.__init__(self, parent)\n        man = CanvasManager.instance()\n        man.sigCanvasListChanged.connect(self.updateCanvasList)\n        self.hostName = None\n        self.updateCanvasList()\n        \n    def updateCanvasList(self):\n        canvases = CanvasManager.instance().listCanvases()\n        canvases.insert(0, \"\")\n        if self.hostName in canvases:\n            canvases.remove(self.hostName)\n            \n        sel = self.currentText()\n        if sel in canvases:\n            self.blockSignals(True)  ## change does not affect current selection; block signals during update\n        self.clear()\n        for i in canvases:\n            self.addItem(i)\n            if i == sel:\n                self.setCurrentIndex(self.count())\n            \n        self.blockSignals(False)\n        \n    def setHostName(self, name):\n        self.hostName = name\n        self.updateCanvasList()\n", "path": "pyqtgraph/canvas/CanvasManager.py"}]}