我有以下类使用额外的 DelegatorParent 类实现“委托设计模式”:
class DelegatorParent():
def __init__(self):
self.a = 'whatever'
class ConcreteDelegatee():
def myMethod(self):
return 'myMethod'
class Delegator(DelegatorParent):
def __init__(self):
self.delegatee = ConcreteDelegatee()
DelegatorParent.__init__(self)
def __getattr__(self, attrname):
return getattr(self.delegatee, attrname)
a = Delegator()
result = a.myMethod()
Run Code Online (Sandbox Code Playgroud)
一切看起来都很好。
现在我想在 DelegatorParent 中放置一个抽象方法,以确保始终定义“myMethod”。
from abc import ABCMeta, abstractmethod
class DelegatorParent():
__metaclass__ = ABCMeta
@abstractmethod
def myMethod(self):
pass
def __init__(self):
self.a = 'whatever'
class ConcreteDelegatee():
def myMethod(self):
return 'myMethod'
class Delegator(DelegatorParent):
def __init__(self):
self.delegatee = ConcreteDelegatee()
DelegatorParent.__init__(self)
def __getattr__(self, attrname):
return getattr(self.delegatee, attrname)
# …Run Code Online (Sandbox Code Playgroud) 我想启动一个微实例来运行一个非常小的任务(不到5分钟),然后终止自己.我计划使用现货实例(因为它更便宜),但我对其他替代方案持开放态度.
如果我这样做,我会收取一小时的费用吗?或者我会被收费,就好像整个小时都使用了实例一样?另外,我是否需要为启动和终止时间付费?或者仅在实例处于活动状态时?
我在AWS FAQs上发现了一个问题:
- 如果我的竞价型实例在小时启动之前被Amazon EC2终止,我会被收费吗? -
不可以.如果竞价型实例被Amazon EC2终止,则不会向您收取部分使用时间的费用.但是,如果您自己终止实例,则会向实例运行的任何小时收取费用.
在我的情况下,实例将由我终止,所以我不确定他们的意思是"如果你自己终止实例,你将被收取实例运行的任何时间".