imp.reload不允许重新加载GPIO

时间:2019-06-07 01:52:08

标签: python-3.x raspberry-pi python-import gpio gpiozero

我正在尝试在Raspberry Pi 3 B +上切换和LED指示灯。我正在导入脚本 import script_name 但是我必须不断地调用所说的脚本。过去我用过 imp.reload(script_name) 以便能够重新调用脚本并传递新变量。当我的脚本命中imp.reload(script_name)时崩溃,提示错误:

Traceback (most recent call last):
  File "/etc/systemd/system/inodev.py", line 63, in <module>
    imp.reload(dmlight_pi)
  File "/usr/lib/python3.5/imp.py", line 314, in reload
    return importlib.reload(module)
  File "/usr/lib/python3.5/importlib/__init__.py", line 166, in reload
    _bootstrap._exec(spec, module)
  File "<frozen importlib._bootstrap>", line 626, in _exec
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in 
_call_with_frames_removed
  File "/etc/systemd/system/dmlight_pi.py", line 28, in <module>
    led.on()
  File "/usr/local/lib/python3.5/dist-packages/gpiozero/output_devices.py", 
line 229, in on
     self._write(True)
  File "/usr/local/lib/python3.5/dist-packages/gpiozero/output_devices.py", 
line 106, in _write
    self.pin.state = self._value_to_state(value)
   File "/usr/local/lib/python3.5/dist-packages/gpiozero/pins/__init__.py", 
line 305, in <lambda>
     lambda self, value: self._set_state(value),
  File "/usr/local/lib/python3.5/dist-packages/gpiozero/pins/pigpio.py", 
line 266, in _set_state
    raise PinSetInput('cannot set state of pin %r' % self)
gpiozero.exc.PinSetInput: cannot set state of pin GPIO24
^CException ignored in: <module 'threading' from 
'/usr/lib/python3.5/threading.py'>
Traceback (most recent call last):
  File "/usr/lib/python3.5/threading.py", line 1288, in _shutdown
    t.join()
  File "/usr/lib/python3.5/threading.py", line 1054, in join
    self._wait_for_tstate_lock()
  File "/usr/lib/python3.5/threading.py", line 1070, in 
_wait_for_tstate_lock
    elif lock.acquire(block, timeout):</code>

我崩溃的脚本是(我正在重新加载的脚本)

import mysql.connector
from __main__ import *
from sainsmart import devices
from gpiozero import LED
from gpiozero.pins.pigpio import PiGPIOFactory
from time import sleep

mydb = mysql.connector.connect(
  host="localhost",
  user="user",
  passwd="password",
  database="database"
)
#print(sys.argv[1])
#data = sys.argv[1]
print(name)
mycursor = mydb.cursor()
mycursor.execute("SELECT * from accounts WHERE name=%s", (name,))
result_set = mycursor.fetchall()
print(result_set)
for row in result_set:
    print(row[5])
    domelight = row[5]
    factory = PiGPIOFactory(host=domelight)
    led = LED(24, pin_factory=factory)
    print(domelight)
    led.on()
    sleep(10)
    led.off()

我要完成的任务是连续循环多次导入python脚本。

0 个答案:

没有答案