Ticket #7101 (closed: fixed)

Opened 7 years ago

Last modified 5 years ago

Crash in PythonAlgorithm using child alg and replacing workspace directly

Reported by: Martyn Gigg Owned by: Martyn Gigg
Priority: blocker Milestone: Release 2.5.3
Component: Mantid Keywords: PatchCandidate,Released
Cc: Blocked By:
Blocking: #7069 Tester: Owen Arnold

Description

This is probably best illustrated with an example. Running the following script in the script window will produce a crash.

from mantid.api import *
from mantid.kernel import *
from mantid.simpleapi import *

class PyClone(PythonAlgorithm):

    def PyInit(self):
        self.declareProperty(MatrixWorkspaceProperty("InputWorkspace", "", Direction.Input))
        self.declareProperty(MatrixWorkspaceProperty("OutputWorkspace", "", Direction.Output))

    def PyExec(self):
        input_ws = self.getProperty("InputWorkspace").value
        outputname = self.getPropertyValue("OutputWorkspace")
        CloneWorkspace(InputWorkspace=input_ws,
                       OutputWorkspace=outputname)
        trans_wc = mtd[outputname]

        self.setProperty("OutputWorkspace", trans_wc)

# Register algorithm with Mantid
AlgorithmFactory.subscribe(PyClone)


#######
mari = Load(Filename="MARI11001.raw")
alg = FrameworkManager.createAlgorithm("PyClone")
alg.setProperty("InputWorkspace", "mari")
alg.setProperty("OutputWorkspace", "testws")
alg.execute()
output_ws = mtd['testws']
print output_ws.name()

If you change the CloneWorkspace call to

        CloneWorkspace(InputWorkspace=input_ws,
                       OutputWorkspace=outputname + "_")
        trans_wc = mtd[outputname + "_"]

then everything is fine as it avoids a replacement at the end of the algorithm.

Change History

comment:1 Changed 7 years ago by Martyn Gigg

Fix crash with Python Algs & WS replacement.

The weak pointers dished out by the ADS weren't being handled properly and a new shared_ptr was created from them when extracting the value from the Python object. This effectively lead to two separate shared_ptr objects, with different use counts, managing the same object. The fix was to ensure the shared pointer is created from the weak pointer using the lock method. Refs #7101

Changeset: ea93cda9907fd6941f3ca6886127eee7d1a07e19

comment:2 Changed 7 years ago by Martyn Gigg

Fix crash with Python Algs & WS replacement.

The weak pointers dished out by the ADS weren't being handled properly and a new shared_ptr was created from them when extracting the value from the Python object. This effectively lead to two separate shared_ptr objects, with different use counts, managing the same object. The fix was to ensure the shared pointer is created from the weak pointer using the lock method. Refs #7101

Changeset: ea93cda9907fd6941f3ca6886127eee7d1a07e19

comment:3 Changed 7 years ago by Martyn Gigg

Fix extractor check. Refs #7101

Changeset: 09982990d17d1bf34c31fb786b7ffa28c88c6f11

comment:4 Changed 7 years ago by Martyn Gigg

Fix extractor check. Refs #7101

Changeset: 09982990d17d1bf34c31fb786b7ffa28c88c6f11

comment:5 Changed 7 years ago by Martyn Gigg

Fix crash with Python Algs & WS replacement.

The weak pointers dished out by the ADS weren't being handled properly and a new shared_ptr was created from them when extracting the value from the Python object. This effectively lead to two separate shared_ptr objects, with different use counts, managing the same object. The fix was to ensure the shared pointer is created from the weak pointer using the lock method. Refs #7101

Changeset: b84edb9974310da28de381dc85718c8ed8662cc0

comment:6 Changed 7 years ago by Martyn Gigg

Fix crash with Python Algs & WS replacement.

The weak pointers dished out by the ADS weren't being handled properly and a new shared_ptr was created from them when extracting the value from the Python object. This effectively lead to two separate shared_ptr objects, with different use counts, managing the same object. The fix was to ensure the shared pointer is created from the weak pointer using the lock method. Refs #7101

Changeset: b84edb9974310da28de381dc85718c8ed8662cc0

comment:7 Changed 7 years ago by Martyn Gigg

  • Owner set to Martyn Gigg
  • Status changed from new to accepted

comment:8 Changed 7 years ago by Martyn Gigg

  • Status changed from accepted to verify
  • Resolution set to fixed

Branch: bugfix/7101_pyalg_crash

Tester: The above script should now not crash!

comment:9 Changed 7 years ago by Owen Arnold

  • Status changed from verify to verifying
  • Tester set to Owen Arnold

comment:10 Changed 7 years ago by Owen Arnold

  • Status changed from verifying to reopened
  • Resolution fixed deleted

Unfortunately, running the original script in the description caused a crash on my Mac. Debug build 10.8:

Crash report:

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   org.mantidproject.MantidPlot  	0x000000010e66a091 boost::shared_ptr<Mantid::API::WorkspaceGroup>::shared_ptr<Mantid::API::Workspace>(boost::shared_ptr<Mantid::API::Workspace> const&, boost::detail::dynamic_cast_tag) + 49 (shared_ptr.hpp:265)
1   org.mantidproject.MantidPlot  	0x000000010e6186b3 boost::shared_ptr<Mantid::API::WorkspaceGroup> boost::dynamic_pointer_cast<Mantid::API::WorkspaceGroup, Mantid::API::Workspace>(boost::shared_ptr<Mantid::API::Workspace> const&) + 83 (shared_ptr.hpp:533)
2   org.mantidproject.MantidPlot  	0x000000010e60012f MantidDockWidget::findParentName(QString const&, boost::shared_ptr<Mantid::API::Workspace>) + 93 (MantidDock.cpp:350)
3   org.mantidproject.MantidPlot  	0x000000010e5fd58b MantidDockWidget::replaceTreeEntry(QString const&, boost::shared_ptr<Mantid::API::Workspace>) + 85 (MantidDock.cpp:245)
4   org.mantidproject.MantidPlot  	0x000000010e7acab9 MantidDockWidget::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) + 741 (moc_MantidDock.cxx:115)

comment:11 Changed 7 years ago by Martyn Gigg

  • Status changed from reopened to accepted

comment:12 Changed 7 years ago by Martyn Gigg

  • Status changed from accepted to verify
  • Resolution set to fixed

comment:13 Changed 7 years ago by Owen Arnold

  • Status changed from verify to verifying

comment:14 Changed 7 years ago by Martyn Gigg

Fix crash with Python Algs & WS replacement.

The weak pointers dished out by the ADS weren't being handled properly and a new shared_ptr was created from them when extracting the value from the Python object. This effectively lead to two separate shared_ptr objects, with different use counts, managing the same object. The fix was to ensure the shared pointer is created from the weak pointer using the lock method. Refs #7101

Changeset: b84edb9974310da28de381dc85718c8ed8662cc0

comment:15 Changed 7 years ago by Owen Arnold

  • Blocking 7069 added

comment:16 Changed 7 years ago by Owen Arnold

  • Status changed from verifying to closed

I've tested this out as follows:

  • Run the original script that crashed it (doesn't crash it any more)
  • Review the code
  • Did a temporary merge of #7069, from which I originally found the issue and tested algorithm (now algorithm works)

comment:17 Changed 7 years ago by Martyn Gigg

  • Keywords PatchCandidate added
  • Milestone changed from Release 2.6 to Release 2.5.3

comment:18 Changed 7 years ago by Martyn Gigg

Fix crash with Python Algs & WS replacement.

The weak pointers dished out by the ADS weren't being handled properly and a new shared_ptr was created from them when extracting the value from the Python object. This effectively lead to two separate shared_ptr objects, with different use counts, managing the same object. The fix was to ensure the shared pointer is created from the weak pointer using the lock method. Refs #7101

Changeset: b84edb9974310da28de381dc85718c8ed8662cc0

comment:19 Changed 7 years ago by Martyn Gigg

Fix crash with Python Algs & WS replacement.

The weak pointers dished out by the ADS weren't being handled properly and a new shared_ptr was created from them when extracting the value from the Python object. This effectively lead to two separate shared_ptr objects, with different use counts, managing the same object. The fix was to ensure the shared pointer is created from the weak pointer using the lock method. Refs #7101

Changeset: b84edb9974310da28de381dc85718c8ed8662cc0

comment:20 Changed 7 years ago by Martyn Gigg

Fix crash with Python Algs & WS replacement.

The weak pointers dished out by the ADS weren't being handled properly and a new shared_ptr was created from them when extracting the value from the Python object. This effectively lead to two separate shared_ptr objects, with different use counts, managing the same object. The fix was to ensure the shared pointer is created from the weak pointer using the lock method. Refs #7101

Changeset: b84edb9974310da28de381dc85718c8ed8662cc0

comment:21 Changed 7 years ago by Martyn Gigg

Merge branch 'bugfix/7101_pyalg_crash' into develop into 6856_ConvertToDiffractionMDWS_v2

comment:22 Changed 7 years ago by Martyn Gigg

Merge branch 'bugfix/7101_pyalg_crash' into develop into 6856_ConvertToDiffractionMDWS_v2

comment:23 Changed 7 years ago by Martyn Gigg

Merge branch 'bugfix/7101_pyalg_crash' into develop into 6856_ConvertToDiffractionMDWS_v2

comment:24 Changed 7 years ago by Martyn Gigg

Merge branch 'bugfix/7101_pyalg_crash' into develop into 6856_ConvertToDiffractionMDWS_v2

comment:25 Changed 7 years ago by Martyn Gigg

Fix crash with Python Algs & WS replacement.

The weak pointers dished out by the ADS weren't being handled properly and a new shared_ptr was created from them when extracting the value from the Python object. This effectively lead to two separate shared_ptr objects, with different use counts, managing the same object. The fix was to ensure the shared pointer is created from the weak pointer using the lock method. Refs #7101

Changeset: a575a6d2dbe065eaba45427a06d8ed52c46d9e8f

comment:26 Changed 7 years ago by Martyn Gigg

Fix extractor check. Refs #7101

Changeset: 66245789b59963a60f1eaa82f5d8844de64aec60

comment:27 Changed 7 years ago by Martyn Gigg

Fix crash with Python Algs & WS replacement.

The weak pointers dished out by the ADS weren't being handled properly and a new shared_ptr was created from them when extracting the value from the Python object. This effectively lead to two separate shared_ptr objects, with different use counts, managing the same object. The fix was to ensure the shared pointer is created from the weak pointer using the lock method. Refs #7101

Changeset: a575a6d2dbe065eaba45427a06d8ed52c46d9e8f

comment:28 Changed 7 years ago by Martyn Gigg

Fix extractor check. Refs #7101

Changeset: 66245789b59963a60f1eaa82f5d8844de64aec60

comment:29 Changed 7 years ago by Nick Draper

  • Keywords PatchCandidate,Released added; PatchCandidate removed

comment:30 Changed 5 years ago by Stuart Campbell

This ticket has been transferred to github issue 7947

Note: See TracTickets for help on using tickets.