使用 eurasia 操作磁盘文件

16 views
Skip to first unread message

沈崴

unread,
Dec 30, 2010, 10:50:32 PM12/30/10
to eurasia-users
首先感谢 bawbaw hu 提交的问题,eurasia 在读取文件时会出现错误:

OSError: [Errno 1] Operation not permitted

由于 epoll 不能处理本地的磁盘文件,当需要使用 eurasia 操作磁盘文件
时可以将后端 patch 成 poll :

#!/usr/bin/python2.6
#-*- coding: utf-8 -*-

# epoll 不支持本地磁盘文件 patch 成 poll
from eurasia.pyev import *
mainloop = default_loop(EVBACKEND_POLL).loop

import os, sys
from eurasia import core
from traceback import print_exc
from eurasia.web import httpserver

# 打开调试输出
core.excepthook = lambda: print_exc(file=sys.stderr)

def handler(httpfile):
httpfile.start_response('200 OK')

# 文件读取
fileno = os.open('test.txt', os.O_RDONLY|os.O_NONBLOCK)
f = core.file(fileno)
s = f.read()
os.close(fileno) # or f.close()

httpfile.sendall(s)
httpfile.close()

httpd = httpserver(':8080', handler)
httpd.start()
mainloop()

Zoom.Quiet

unread,
Dec 30, 2010, 11:25:12 PM12/30/10
to eurasi...@googlegroups.com
2010/12/31 沈崴 <wile...@gmail.com>:

> 首先感谢 bawbaw hu 提交的问题,eurasia 在读取文件时会出现错误:
>
>    OSError: [Errno 1] Operation not permitted
>
> 由于 epoll 不能处理本地的磁盘文件,当需要使用 eurasia 操作磁盘文件
> 时可以将后端 patch 成 poll :
>

嗯嗯嗯,这是非常现实的需求,增补到维基中吧

> #!/usr/bin/python2.6
> #-*- coding: utf-8 -*-
>
> # epoll 不支持本地磁盘文件 patch 成 poll
> from eurasia.pyev import *
> mainloop = default_loop(EVBACKEND_POLL).loop
>
> import os, sys
> from eurasia import core
> from traceback import print_exc
> from eurasia.web import httpserver
>
> # 打开调试输出
> core.excepthook = lambda: print_exc(file=sys.stderr)
>
> def handler(httpfile):
>    httpfile.start_response('200 OK')
>
>    # 文件读取
>    fileno = os.open('test.txt', os.O_RDONLY|os.O_NONBLOCK)
>    f = core.file(fileno)
>    s = f.read()
>    os.close(fileno) # or f.close()
>
>    httpfile.sendall(s)
>    httpfile.close()
>
> httpd = httpserver(':8080', handler)
> httpd.start()
> mainloop()
>

> --
> 您收到此邮件是因为您订阅了 Google 网上论坛的“eurasia-users”论坛。
> 要向此网上论坛发帖,请发送电子邮件至 eurasi...@googlegroups.com
> 要取消订阅此网上论坛,请发送电子邮件至 eurasia-user...@googlegroups.com
> 若有更多问题,请通过 http://groups.google.com/group/eurasia-users?hl=zh-CN 访问此网上论坛。
>
>

--
人生苦短, Pythonic!
俺: http://about.me/zoom.quiet
开: http://code.ijinshan.com/
豆: http://www.douban.com/group/zoomquiet
书: http://code.google.com/p/openbookproject
蟒: http://code.google.com/p/kcpycamp/wiki/PythoniCamp

沈崴

unread,
Dec 31, 2010, 1:26:21 AM12/31/10
to eurasia-users
OK

On 12月31日, 上午4时25分, "Zoom.Quiet" <zoom.qu...@gmail.com> wrote:
> 2010/12/31 沈崴 <wilei...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages