当前位置: 首页>>代码示例>>Python>>正文


Python ThreadPool.stop方法代码示例

本文整理汇总了Python中threadpool.ThreadPool.stop方法的典型用法代码示例。如果您正苦于以下问题:Python ThreadPool.stop方法的具体用法?Python ThreadPool.stop怎么用?Python ThreadPool.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在threadpool.ThreadPool的用法示例。


在下文中一共展示了ThreadPool.stop方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ThreadedRunner

# 需要导入模块: from threadpool import ThreadPool [as 别名]
# 或者: from threadpool.ThreadPool import stop [as 别名]
class ThreadedRunner(BaseRunner):
    "Run tests using a threadpool"

    def __init__(self, num_threads):
        BaseRunner.__init__(self)
        from threadpool import ThreadPool
        self.pool = ThreadPool(num_threads)
        self.pool.start()

    def run(self, fixture):
        BaseRunner.run(self, fixture)
        self.pool.dispatch(fixture, self.reporter)

    def done(self):
        self.pool.stop()
        BaseRunner.done(self)
开发者ID:algard,项目名称:testoob,代码行数:18,代码来源:threadedrunner.py

示例2: __init__

# 需要导入模块: from threadpool import ThreadPool [as 别名]
# 或者: from threadpool.ThreadPool import stop [as 别名]
class Scanner:
	def __init__( self, kb, cfg, targets, edispatcher ):
		self.kb      = kb
		self.cfg     = cfg
		self.targets = targets
		self.pool	 = ThreadPool( window_size = self.cfg.Threads, prototype = ScannerThread, async = False )
		self.ed		 = edispatcher
		
	def start( self ):
		for target in self.targets:
			for kbitem in self.kb.items:
				self.pool.pushArgs( kbitem, target, self.ed )
				
		self.pool.start()
		
	def stop( self ):
		self.pool.stop()
		
	def running( self ):
		return self.pool.active
开发者ID:evilsocket,项目名称:altair,代码行数:22,代码来源:scanner.py

示例3: __init__

# 需要导入模块: from threadpool import ThreadPool [as 别名]
# 或者: from threadpool.ThreadPool import stop [as 别名]
class Database:
    """Asynchronous database interface.

    The `driver' argument specifies which database to use. Possible
    values are:

    MySQLdb - for MySQL
    psycopg2 - for Postgres
    """
    def __init__(self,
                 driver=None,
                 database=None, user=None, password=None,
                 host='localhost',
                 ioloop=tornado.ioloop.IOLoop.instance(),
                 num_threads=10,
                 tx_connection_pool_size=5,
                 queue_timeout=1,
                 thread_idle_life=60*60):
        if not(driver):
            raise ValueError("Missing 'driver' argument")
        self._driver = driver
        self._database = database
        self._user = user
        self._password = password
        self._host = host
        self._threadpool = ThreadPool(
            per_thread_init_func=self.create_connection,
            per_thread_close_func=self.close_connection,
            num_threads=num_threads,
            queue_timeout=queue_timeout,
            thread_idle_life=thread_idle_life)
        self._ioloop = ioloop

        # Connection pool for transactions
        self._connection_pool = []
        for i in xrange(tx_connection_pool_size):
            conn = self.create_connection()
            self._connection_pool.append(conn)
        self._waiting_on_connection = deque()

    def create_connection(self):
        """This method is executed in a worker thread.

        Initializes the per-thread state. In this case we create one
        database connection per-thread.
        """
        # if self._driver == "psycopg2":
        #     try:
        #         import psycopg2
        #         conn = psycopg2.connect(database=self._database,
        #                                 user=self._user,
        #                                 password=self._password,
        #                                 host=self._host)
        #     except Exception as ex:
        #         raise ex
        if self._driver == "MySQLdb":
            try:
                import MySQLdb
                conn = MySQLdb.connect(db=self._database,
                                       user=self._user,
                                       passwd=self._password,
                                       host=self._host,
                                       port=3306)
            except Exception as ex:
                raise ex
        else:
            raise ValueError("Unknown driver %s" % self._driver)
        return conn

    def close_connection(self, conn):
        conn.close()

    def stop(self):
        self._threadpool.stop()
        for conn in self._connection_pool:
            conn.close()

    @async
    def beginTransaction(self, callback):
        """Begins a transaction. Picks up a transaction from the pool
        and passes it to the callback. If none is available, adds the
        callback to `_waiting_on_connection'.
        """
        if self._connection_pool:
            conn = self._connection_pool.pop()
            callback(conn)
        else:
            self._waiting_on_connection.append(callback)

    @async
    def commitTransaction(self, connection, callback):
        self._threadpool.add_task(
            partial(self._commitTransaction, connection, callback))

    def _commitTransaction(self, conn, callback, thread_state=None):
        """Invoked in a worker thread.
        """
        conn.commit()
        self._ioloop.add_callback(
            partial(self._releaseConnectionInvokeCallback, conn, callback))
#.........这里部分代码省略.........
开发者ID:henyouqian,项目名称:hanzi,代码行数:103,代码来源:adb.py

示例4: MyHttp

# 需要导入模块: from threadpool import ThreadPool [as 别名]
# 或者: from threadpool.ThreadPool import stop [as 别名]
			self.write("<h1>Not Found</h1>Sorry, no such page.")
			self.finish( )

class MyHttp(http.HTTPChannel):
    requestFactory = FunctionHandledRequest

class MyHttpFactory(http.HTTPFactory):
    protocol = MyHttp


def loopquery():
	StartSend()
	reactor.callLater(1, loopquery)


if __name__ == "__main__":
	port = cfg.port
	os.system("title EmailSender - PS")
	print "Start OK", "port:", port
	try:
		tempdb.createTable()
	except:
		pass
	reactor.listenTCP(port, MyHttpFactory( ))
	reactor.callLater(1, loopquery)
	reactor.run( )
	print "Stoping"
	tp.stop()


开发者ID:bahamut8348,项目名称:xkcode,代码行数:30,代码来源:emailsender.py


注:本文中的threadpool.ThreadPool.stop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。