示例#1
0
import os
import sys
import time
import urlparse
import urllib2
from eventlet import event
from eventlet.green import subprocess
from eventlet import greenthread

from weibo import exception
from weibo.common.gettextutils import _
from weibo.common import jsonutils
from weibo.common import log as logging

LOG = logging.getLogger(__name__)


def conn_img_url(bigurl, ntime=3):
    while ntime > 0:
        try:
            time.sleep(3)
            urllib2.urlopen(bigurl)
        except Exception:
            ntime = ntime - 1
        else:
            break

    if ntime < 1:
        raise exception.ConnNotUrl(url=bigurl)

示例#2
0
"""Session Handling for SQLAlchemy backend."""

import re
import time

from sqlalchemy.exc import DisconnectionError, OperationalError
import sqlalchemy.interfaces
import sqlalchemy.orm
from sqlalchemy.pool import NullPool, StaticPool

from weibo.common import cfg
from weibo.common import log as logging


LOG = logging.getLogger(__name__)
CONF = cfg.CONF
_ENGINE = None
_MAKER = None


def ping_listener(dbapi_conn, connection_rec, connection_proxy):
    """
    Ensures that MySQL connections checked out of the
    pool are alive.

    Borrowed from:
    http://groups.google.com/group/sqlalchemy/msg/a4ce563d802c929f
    """
    try:
        dbapi_conn.cursor().execute('select 1')
    except dbapi_conn.OperationalError, ex: