( self )
| 176 | |
| 177 | @unittest.skipIf( ( IECore.TestUtil.inMacCI() or IECore.TestUtil.inWindowsCI() ), "Mac and Windows CI are too slow for reliable timing" ) |
| 178 | def testCancelLoading( self ) : |
| 179 | |
| 180 | strip = IECoreScene.MeshPrimitive.createPlane( imath.Box2f( imath.V2f( 0 ), imath.V2f( 100000, 1 ) ), imath.V2i( 1000000, 1 ) ) |
| 181 | testData = IECore.FloatVectorData( [0] * ( len( strip["P"].data ) ) ) |
| 182 | for i in range( 10 ): |
| 183 | q = IECore.FloatVectorData( testData ) |
| 184 | q[0] = i |
| 185 | strip["var%i" % i] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, q ) |
| 186 | |
| 187 | saveIO = IECore.MemoryIndexedIO( IECore.CharVectorData(), IECore.IndexedIO.OpenMode.Write ) |
| 188 | strip.save( saveIO, "test" ) |
| 189 | loadIO = IECore.MemoryIndexedIO( saveIO.buffer(), IECore.IndexedIO.OpenMode.Read ) |
| 190 | |
| 191 | canceller = IECore.Canceller() |
| 192 | cancelled = [False] |
| 193 | |
| 194 | def backgroundRun(): |
| 195 | try: |
| 196 | IECore.Object.load( loadIO, "test", canceller ) |
| 197 | except IECore.Cancelled: |
| 198 | cancelled[0] = True |
| 199 | |
| 200 | thread = threading.Thread(target=backgroundRun, args=()) |
| 201 | |
| 202 | startTime = time.time() |
| 203 | thread.start() |
| 204 | |
| 205 | time.sleep( 0.01 ) |
| 206 | canceller.cancel() |
| 207 | thread.join() |
| 208 | |
| 209 | self.assertLess( time.time() - startTime, 0.1 ) |
| 210 | self.assertTrue( cancelled[0] ) |
| 211 | |
| 212 | if __name__ == "__main__": |
| 213 | unittest.main() |
nothing calls this directly
no test coverage detected