从动态更新txt文件中读取最后一行

时间:2015-03-01 07:57:46

标签: javascript python flask

我有一个小烧瓶应用程序,在运行时将一些输出写入txt文件。是否可以从同一文件中读取更新的最后一行?我猜猜JS有可能吗?

多处理没有用于读取文件的某些原因。这是我尝试多处理时的回溯:



Process Process-2:
Process Process-2:
Traceback (most recent call last):
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 114, in run
    self._target(*self._args, **self._kwargs)
    self.run()
  File "app.py", line 24, in read
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 114, in run
    self._target(*self._args, **self._kwargs)
  File "app.py", line 24, in read
    pose = subprocess.check_output(['tail', '-1', 'pose.txt'])
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 566, in check_output
    pose = subprocess.check_output(['tail', '-1', 'pose.txt'])
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 566, in check_output
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 709, in __init__
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 709, in __init__
    errread, errwrite)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1307, in _execute_child
    data = _eintr_retry_call(os.read, errpipe_read, 1048576)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 476, in _eintr_retry_call
    errread, errwrite)
    return func(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1312, in _execute_child
    _close_in_parent(c2pwrite)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1207, in _close_in_parent
    def _close_in_parent(fd):
KeyboardInterrupt
KeyboardInterrupt




这是我的基本代码。



f = open('pose.txt', 'r')
.
.
.~bunch of codes~
.
.

if __name__ == "__main__":
	writing = multiprocessing.Process(target=writer)
	writing.start()
	app.run(debug=True)




0 个答案:

没有答案