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


Python Process.isRunning方法代码示例

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


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

示例1: Bot

# 需要导入模块: from process import Process [as 别名]
# 或者: from process.Process import isRunning [as 别名]
class Bot(gobject.GObject):
	""""""

	# custom properties
	__gproperties__ = {
		'apiAccessible' : (gobject.TYPE_BOOLEAN, 'api accessible', 'is api accessible', False, gobject.PARAM_READWRITE),
		'isRunning' : (gobject.TYPE_BOOLEAN, 'is running', 'is running', False, gobject.PARAM_READWRITE)
	}

	CHANNEL_TELL = 0
	CHANNEL_ORG = 1
	CHANNEL_PRIVATE = 2
 
	def __init__(self, name, settingModel):
		"""Constructor method."""
		self.__gobject_init__()
		self.name = name
		self.settingModel = settingModel
		self.api = budapi.Budapi()
		self.process = Process()
		self.consoleModel = gtk.TextBuffer()
		self.configFile = None
		self.noRestart = False
		self.set_property('apiAccessible', False)
		self.process.connect('stdout_received', self.onBotStdoutReceived)
		self.process.connect('stderr_received', self.onBotStderrReceived)
		self.process.connect('stopped', self.onBotDied)

		tagTable = self.consoleModel.get_tag_table()

		def addTag(buffer, name, foreground, weight = None):
			"""Adds a text tag to buffer with given name and styles."""
			tag = gtk.TextTag(name)
			tag.set_property('foreground', foreground)
			if weight != None:
				tag.set_property('weight', weight)
			buffer.get_tag_table().add(tag)

		addTag(self.consoleModel, 'error', foreground = 'red', weight = pango.WEIGHT_BOLD)
		addTag(self.consoleModel, 'response', foreground = 'lightblue')


	def do_get_property(self, property):
		"""Returns value of given property.
		This is required to make GTK's properties to work.
		See: http://www.pygtk.org/articles/subclassing-gobject/sub-classing-gobject-in-python.htm#d0e127
		"""
		if property.name == 'apiAccessible':
			return self.apiAccessible
		elif property.name == 'isRunning':
			return self.process.isRunning()
		else:
			raise AttributeError, 'unknown property %s' % property.name

	def do_set_property(self, property, value):
		"""Sets value of given property.
		This is required to make GTK's properties to work.
		See: http://www.pygtk.org/articles/subclassing-gobject/sub-classing-gobject-in-python.htm#d0e127
		"""
		if property.name == 'apiAccessible':
			self.apiAccessible = value
		else:
			raise AttributeError, 'unknown property %s' % property.name

	def getName(self):
		"""Returns name of the bot."""
		return self.name

	def getConsoleModel(self):
		"""Returns console model"""
		return self.consoleModel

	def start(self):
		"""Starts the bot."""
		# do nothing if bot process is still running.
		if self.process.isRunning():
			return

		configPath = self.settingModel.getValue(self.name, 'configfile')
		self.configFile = BotPhpConfigFile(configPath)
		self.configFile.load()
		port = self.configFile.getVar('API Port')

		# make sure that port is within defined range
		lowPort  = self.settingModel.getApiPortRangeLow()
		highPort = self.settingModel.getApiPortRangeHigh()
		if port < lowPort or port > highPort:
			port = lowPort
			self.configFile.setVar('API Port', port)
			self.configFile.save()

		# find a free port if currently set port is not free
		if self.isPortFree(port) == False:
			for port in range(lowPort, highPort + 1):
				if self.isPortFree(port):
					self.configFile.setVar('API Port', port)
					self.configFile.save()
					break

		self.noRestart = False
#.........这里部分代码省略.........
开发者ID:farthing,项目名称:Budabot,代码行数:103,代码来源:bot.py


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