frame

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Alert: Beginning Tuesday, June 25th, we will be freezing this site and migrating the content and forums to our new home at https://forums.intel.com/s/topic/0TO0P000000PqZDWA0/intel-neural-compute-sticks. Check it out now!

How to close already open Device

If my (python) application crashes in a bad way (I know bad exception handling... but I'm getting there!) the device is not closed at all before the script exits. When I rerun the application, the device can't be opened anymore nor closed. So far only a reboot of the Raspberry helped to free the device again. My Raspi is downstairs and I don't want to go and unplug and re-plug the stick, so I haven't tested whether that would work. Does anybody have a beautiful solution to re-initialize the stick? Best would be through the API of course, but it seems not possible to me. It might only be possible through resetting the USB device with something like this, right?

Comments

  • 1 Comment sorted by Votes Date Added
  • @dominicbosch, you might be running into 1 of 2 issues I can think of:

    1. Your program/process is still holding the resource
    2. The firmware on NCS is stuck in an unknown state

    Both cases will give you the following error:

    Traceback (most recent call last):
      File "image-classifier.py", line 36, in <module>
        device.OpenDevice()
      File "/usr/local/lib/python3.5/dist-packages/mvnc/mvncapi.py", line 147, in OpenDevice
        raise Exception(Status(status))
    Exception: mvncStatus.ERROR
    

    For the second case (The firmware on NCS is stuck in an unknown state):
    As of today, the only option is to power cycle the device (unplug & re-plug). We use an Ethernet relay controller that kills VBUS power, which is a pricier option.

    For the first case (Your program/process is still holding the resource):
    When a python app crashes, or it is manually terminated with a ctrl+c event, or you forget to close device (release resource) before exiting, the python interpreter is supposed to release all resources held by that app. Try these examples:

    Example 1: If your app crashes and manages to evade the python interpreter to gracefully exit, kill the python3 process and rerun your app

    python3 image-classifier.py 
    # Let's say app crashes here without releasing resources. Get the PID for  your program (it's actually python3 PID)
    ps ax | grep image-classifier.py 
    21436 pts/12   Sl+    0:01 python3 image-classifier.py
    21492 pts/13   S+     0:00 grep --color=auto image-classifier.py
    
    # Kill python3 PID
    kill -9 21436
    ps ax | grep image-classifier.py 
    21492 pts/13   S+     0:00 grep --color=auto image-classifier.py
    
    # Rerun the app
    python3 image-classifier.py
    ------- predictions --------
    prediction 0 is n02123159 tiger cat
    prediction 1 is n02123045 tabby, tabby cat
    prediction 2 is n02124075 Egyptian cat
    prediction 3 is n02127052 lynx, catamount
    

    Example 2: Hit ctrl+c after running image-classifier.py, and before closing the image window. Re-run image-classifier.py and see what happens.

    cd ~/workspace/ncappzoo/apps/image-classifier
    python3 image-classifier.py 
    ------- predictions --------
    prediction 0 is n02123159 tiger cat
    prediction 1 is n02123045 tabby, tabby cat
    prediction 2 is n02124075 Egyptian cat
    prediction 3 is n02127052 lynx, catamount
    
    # Hit ctrl+c
    ^C
        Tk.mainloop()
      File "/usr/lib/python3.5/tkinter/__init__.py", line 408, in mainloop
        _default_root.tk.mainloop(n)
    KeyboardInterrupt
    
    # Rerun the app
    python3 image-classifier.py 
    ------- predictions --------
    prediction 0 is n02123159 tiger cat
    prediction 1 is n02123045 tabby, tabby cat
    prediction 2 is n02124075 Egyptian cat
    prediction 3 is n02127052 lynx, catamount
    

    Example 3: Comment out device.CloseDevice() from image-classifier.py and run it multiple times.

    # Excerpt from image-classifier.py
    # ---- Step 5: Unload the graph and close the device -------------------------
    
    #graph.DeallocateGraph()
    #device.CloseDevice()
    
    python3 image-classifier.py
    ------- predictions --------
    prediction 0 is n02123159 tiger cat
    prediction 1 is n02123045 tabby, tabby cat
    prediction 2 is n02124075 Egyptian cat
    prediction 3 is n02127052 lynx, catamount
    python3 image-classifier.py
    ------- predictions --------
    prediction 0 is n02123159 tiger cat
    prediction 1 is n02123045 tabby, tabby cat
    prediction 2 is n02124075 Egyptian cat
    prediction 3 is n02127052 lynx, catamount
    
Sign In or Register to comment.