python IOerror:[Errno 22]threading.thread中的参数无效

python IOerror:[Errno 22]threading.thread中的参数无效,python,multithreading,Python,Multithreading,我尝试以threading.thread的形式写入sysfs 它在没有线程的情况下工作: f = open('/sys/class/pwm/pwmchip0/pwm0/duty_cycle', 'w') f.write(str(100)) f.close() 但如果我把它放在一根线里: import threading class Thread(threading.Thread): def __init__(self): threading.Thread.__init__(

我尝试以threading.thread的形式写入sysfs

它在没有线程的情况下工作:

f = open('/sys/class/pwm/pwmchip0/pwm0/duty_cycle', 'w')
f.write(str(100))
f.close()
但如果我把它放在一根线里:

import threading

class Thread(threading.Thread):
   def __init__(self):
      threading.Thread.__init__(self)

   def run(self):
       while True:
          f = open('/sys/class/pwm/pwmchip0/pwm0/duty_cycle', 'w')
          f.write(str(100))
          f.close()
          time.sleep(1)

 t = Thread()
 t.start()
其结果是:

Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
    self.run()
  File "/home/steve/test.py", line 10, in run
    f.close()
IOError:[Errno 22]参数无效

如果在f.close()之前添加f.flush(),则f.flush()会发生相同的错误。 看起来线程对sysfs的权限与主线程不同。 即使在写块周围添加锁也不能阻止它。 为什么会发生这种情况?我怎样才能避开它