Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot initialize Blink1() twice in the same process #3

Open
vejuhust opened this issue Apr 6, 2018 · 0 comments
Open

Cannot initialize Blink1() twice in the same process #3

vejuhust opened this issue Apr 6, 2018 · 0 comments

Comments

@vejuhust
Copy link
Contributor

vejuhust commented Apr 6, 2018

This issue is easy to reproduce --- with a little change to the demo usage like this:

import time
from blink1.blink1 import blink1

with blink1() as b1:
    b1.fade_to_color(100, 'navy')
    time.sleep(3)

with blink1() as b1:
    b1.fade_to_color(100, 'pink')
    time.sleep(3)

Following error will be thrown while executing the 2nd with:

Traceback (most recent call last):
  File "bug_blink2.py", line 9, in <module>
    b1.fade_to_color(100, 'pink')
  File "/Users/Vej/.virtualenvs/nb/lib/python3.5/site-packages/blink1/blink1.py", line 179, in fade_to_color
    return self.fade_to_rgb(fade_milliseconds, red, green, blue)
  File "/Users/Vej/.virtualenvs/nb/lib/python3.5/site-packages/blink1/blink1.py", line 152, in fade_to_rgb
    return self.fade_to_rgb_uncorrected(fade_milliseconds, r, g, b, led_number)
  File "/Users/Vej/.virtualenvs/nb/lib/python3.5/site-packages/blink1/blink1.py", line 148, in fade_to_rgb_uncorrected
    self.write( buf )
  File "/Users/Vej/.virtualenvs/nb/lib/python3.5/site-packages/blink1/blink1.py", line 127, in write
    self.dev.send_feature_report(buf)
AttributeError: 'NoneType' object has no attribute 'send_feature_report'

I also tried two various versions, both got the same error on the 2nd call:

Version1:

def light_on(color = 'navy'):
    with blink1() as b1:
        print("dev", b1)
        b1.fade_to_color(100, color)
        sleep(3)

light_on('red')
light_on('yellow')
light_on('blue')

Version2:

def light_on(color = 'navy'):
    b1 = Blink1()
    print("dev", b1.dev)
    b1.fade_to_color(100, color)
    sleep(3)
    b1.off()
    b1.close()

light_on('blue')
light_on('yellow')
light_on('red')

It seems that the close method of the first Blink1() didn't release the device which made the second Blink1() fail to find the blink(1) while initializing.

About my environment, I have one blink(1) mk connected to my Mac ---

Darwin VM.local 16.7.0 Darwin Kernel Version 16.7.0: Thu Jan 11 22:59:40 PST 2018; root:xnu-3789.73.8~1/RELEASE_X86_64 x86_64

Python Version ---

Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 26 2016, 10:47:25)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin

Python packages (i.e. output of pip freeze)---

blink1==0.1.3
click==6.7
hidapi==0.7.99.post21
webcolors==1.8.1

Please fix this, thanks!

vejuhust added a commit to vejuhust/blink1-python that referenced this issue Apr 19, 2018
todbot added a commit that referenced this issue Apr 19, 2018
Fix Issue #3 - Blink(1) device not released after being closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant