小编Dav*_*lli的帖子

如何在Go中处理i18n?

我在网上搜索,但没有找到任何与i18n和Go有关的内容.

我希望使用Go开发网站.处理国际化的最佳方式是什么?

internationalization go

21
推荐指数
3
解决办法
9342
查看次数

由urllib2阻止的Python进程

我设置了一个进程来读取要下载的传入URL的队列,但是当urllib2打开连接时系统挂起.

import urllib2, multiprocessing
from threading import Thread
from Queue import Queue
from multiprocessing import Queue as ProcessQueue, Process

def download(url):
    """Download a page from an url.
    url [str]: url to get.
    return [unicode]: page downloaded.
    """
    if settings.DEBUG:
        print u'Downloading %s' % url
    request = urllib2.Request(url)
    response = urllib2.urlopen(request)
    encoding = response.headers['content-type'].split('charset=')[-1]
    content = unicode(response.read(), encoding)
    return content

def downloader(url_queue, page_queue):
    def _downloader(url_queue, page_queue):
        while True:
            try:
                url = url_queue.get()
                page_queue.put_nowait({'url': url, 'page': download(url)})
            except Exception, err:
                print u'Error …
Run Code Online (Sandbox Code Playgroud)

python multithreading urllib2 multiprocess

8
推荐指数
1
解决办法
2232
查看次数