Arduino YUN and Linux contact with firmata

I want to use Linux python to read and write Arduino port data as quick as possible. I try to use firmata contact between Arduino and Linux. At the end I write a txt file to save my data,but it seems I don’t contact to Arduino port successfully . Here is my code.

Python

import wave
import random
import struct
import datetime
import time,os
from pyfirmata import Arduino, util
from time import sleep
import sys

port='/dev/ttyATH0'
board=Arduino(port)
it =util.Iterator(board)
it.start()
a1=board.get_pin('a:1:i')

SAMPLE_LEN = 8000 * 1 


f=open('/mnt/sda1/qwes5.txt','w')

sleep(0.1)
d1 = time.time()
for i in range(0, SAMPLE_LEN):
 f.write(str(a1.read())+'\n')
 
 
d2 = time.time()
print(SAMPLE_LEN/(d2-d1))
f.close()
board.exit()

Arduino
I use this firmata example for YUN

Sometimes I got a file but sometimes error
error code

Traceback (most recent call last):
  File "ZXCV.py", line 11, in <module>
    board=Arduino(port)
  File "/usr/lib/python2.7/site-packages/pyfirmata/__init__.py", line 16, in __i                                    nit__
    super(Arduino, self).__init__(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/pyfirmata/pyfirmata.py", line 86, in __                                    init__
    while self.bytes_available():
  File "/usr/lib/python2.7/site-packages/pyfirmata/pyfirmata.py", line 225, in b                                    ytes_available
    return self.sp.inWaiting()
  File "/usr/lib/python2.7/site-packages/serial/serialposix.py", line 346, in in                                    Waiting
    s = fcntl.ioctl(self.fd, TIOCINQ, TIOCM_zero_str)
IOError: [Errno 5] Input/output error