How to run two functions simultaneously

后端 未结 4 377
[愿得一人]
[愿得一人] 2020-12-17 15:07

I am running test but I want to run 2 functions at the same time. I have a camera and I am telling it to move via suds, I am then logging into the camera via SSH to check th

4条回答
  •  無奈伤痛
    2020-12-17 15:32

    Import the threading module and run SudsMove() like so:

    threading.Thread(target = SudsMove).start()
    

    That will create and start a background thread which does the movement.

    ANSWER TO EDITED QUESTION:

    As far as I understand this, TestAbsoluteMove.Ssh(self) polls the speed once and stores the result in self.Value?! And you're testing the expected end tilt/rotation/position with self.assertEqual(self.Value, '3500')?!

    If that's correct, you should wait for the camera to start its movement. You could probably poll the speed in a certain interval:

    # Move camera in background thread
    threading.Thread(target = SudsMove).start()
    
    # What does this do?
    self.command = './ptzpanposition -c 0 -u degx10'
    
    # Poll the current speed in an interval of 250 ms
    import time
    measuredSpeedsList = []
    
    for i in xrange(20):
        # Assuming that this call will put the result in self.Value
        TestAbsoluteMove.Ssh(self)
        measuredSpeedsList.append(self.Value)
        time.sleep(0.25)
    
    print "Measured movement speeds: ", measuredSpeedsList
    

    The movement speed will be the biggest value in measuredSpeedsList (i.e. max(measuredSpeedsList)). Hope that makes sense...

提交回复
热议问题