是否可以在Route 53中为另一个AWS账户中的资源创建别名记录?
使用案例:
我有2个AWS账户.我的域配置在一个帐户托管区,我在账户B.一个ELB我要为我的域的区域顶点建立在B账户到我的ELB的纪录 - 这在帐户A.进行配置
有谁知道我怎么能解决这个问题?我知道我可以通过结算支持将域名转移到帐户B但我不想这样做.此外,将资源从帐户B迁移到帐户A是不可行的.
我有以下课程.它允许我通过java执行命令.
public class ExecuteShellCommand {
public String executeCommand(String command) {
StringBuffer output = new StringBuffer();
Process p;
try {
p = Runtime.getRuntime().exec(command);
p.waitFor();
BufferedReader reader =
new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = reader.readLine())!= null) {
output.append(line + "\n");
}
} catch (Exception e) {
e.printStackTrace();
}
return output.toString();
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行命令时,不保存上一个命令的结果.例如:
public static void main(String args[]) {
ExecuteShellCommand com = new ExecuteShellCommand();
System.out.println(com.executeCommand("ls"));
System.out.println(com.executeCommand("cd bin"));
System.out.println(com.executeCommand("ls"));
}
Run Code Online (Sandbox Code Playgroud)
给出输出:
bin
src
bin
src
Run Code Online (Sandbox Code Playgroud)
为什么第二个'ls'命令没有显示'bin'目录的内容?
我正在尝试创建一个在后台执行操作的线程.我需要能够在需要时有效地"暂停"它,并在以后再次"恢复"它.此外,如果线程在我"暂停"它时正在做某事,它应该让调用线程等到它完成它正在做的事情.
我对Python中的多线程很新,所以我还没有那么远.
除了让调用线程等待,如果在我的线程正在执行某些操作时调用暂停,我几乎可以做的事情.
以下是我在代码中尝试实现的概述:
import threading, time
class Me(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
#flag to pause thread
self.paused = False
def run(self):
while True:
if not self.paused:
#thread should do the thing if
#not paused
print 'do the thing'
time.sleep(5)
def pause(self):
self.paused = True
#this is should make the calling thread wait if pause() is
#called while the thread is 'doing the thing', until it is
#finished 'doing the thing'
#should just resume the thread
def resume(self):
self.paused = False …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Flask Framework在JQuery和Python上进行长时间的轮询.
在PHP之前完成了长时间的轮询,我试图以同样的方式进行:
具有while(true)循环的脚本/函数,定期检查更改,例如数据库中每0.5秒,并在发生更改时返回一些数据.
所以在我的ini .py中我创建了一个app.route to/poll for JQuery to call.JQuery为它提供了有关客户端当前状态的一些信息,并且poll()函数将其与数据库中当前的状态进行了比较.循环结束并在观察到变化时返回信息.
这是python代码:
@app.route('/poll')
def poll():
client_state = request.args.get("state")
#remove html encoding + whitesapce from client state
html_parser = HTMLParser.HTMLParser()
client_state = html_parser.unescape(client_state)
client_state = "".join(client_state.split())
#poll the database
while True:
time.sleep(0.5)
data = get_data()
json_state = to_json(data)
json_state = "".join(data) #remove whitespace
if json_state != client_state:
return "CHANGE"
Run Code Online (Sandbox Code Playgroud)
问题是,当上面的代码开始轮询时,服务器似乎被重载和其他Ajax调用,而其他请求,如使用JQuery将"加载"图像加载到html是无响应和超时.
为了完成起见,我在这里包含了JQuery:
function poll() {
queryString = "state="+JSON.stringify(currentState);
$.ajax({
url:"/poll",
data: queryString,
timeout: 60000,
success: function(data) {
console.log(data);
if(currentState == null) …Run Code Online (Sandbox Code Playgroud) 使用SQLAlchemy,如果我的数据库中有一个唯一的列,例如,用户名:
username = db.Column(db.String(50), unique=True)
Run Code Online (Sandbox Code Playgroud)
当我添加一个违反此约束的行时,我正在尝试添加的用户名已存在,则抛出IntegrityError:
IntegrityError: (IntegrityError) (1062, u"Duplicate entry 'test' for key 'username'")
Run Code Online (Sandbox Code Playgroud)
是否可以将约束的中断映射到自定义异常?eg.UsernameExistsError
我希望能够捕获单个约束中断,并将响应发送回用户.例如:"此用户名已被使用"
这可能吗?或者下一个最好的东西是什么?
任何指导将不胜感激:)
我正在尝试使用 SQLAlchemy 对我的数据库进行级联删除。我有表格(删除了不相关的字段):
action_permissions_to_groups = db.Table('action_permissions_to_groups',
db.Column('group_id', db.Integer, db.ForeignKey('group.id', ondelete='cascade')),
db.Column('action_permission_id', db.Integer, db.ForeignKey('action_permission.id', ondelete='cascade'))
)
class Group(db.Model, MyModel):
id = db.Column(db.Integer, primary_key=True)
action_permissions = db.relationship('ActionPermission', secondary=action_permissions_to_groups, cascade='delete')
class ActionPermission(db.Model, MyModel):
id = db.Column(db.Integer, primary_key=True)
Run Code Online (Sandbox Code Playgroud)
在英语中,多个Groups有多个ActionPermissions。当我删除 a 时Group,我希望action_permissions_to_groups删除表中与要删除group_id的组匹配的所有行中的所有内容。
当我尝试删除一个组时,上面的代码给了我以下错误:
InvalidRequestError:由于刷新期间先前的异常,此会话的事务已回滚。要使用此会话开始新事务,请首先发出 Session.rollback()。原始异常是:表“action_permissions_to_groups”上的 DELETE 语句预期删除 11 行;只有 12 个匹配。
有谁知道我做错了什么?
谢谢!!
我在 Python 中导入时遇到了一些问题。
这是一个简单的例子来说明问题所在。
我有一个这样的目录结构:
app
|---__init__.py
|---sub_app
|---__init__.py
Run Code Online (Sandbox Code Playgroud)
代码:
应用程序/__init__.py
shared_data = {
'data': 123
}
from sub_app import more_shared_data
print more_shared_data
Run Code Online (Sandbox Code Playgroud)
应用程序/sub_app/__init__.py
more_shared_data = {
'data': '12345'
}
from app import shared_data
print shared_data
Run Code Online (Sandbox Code Playgroud)
但是我收到错误:
ImportError: No module named app
Run Code Online (Sandbox Code Playgroud)
如何将shared_data字典导入app/sub_app/__init__.py?
我为我正在构建的应用程序创建了一个简单的初始化脚本。脚本的开始部分如下所示:
user="ec2-user"
name=`basename $0`
pid_file="/var/run/python_worker.pid"
stdout_log="/var/log/worker/worker.log"
stderr_log="/var/log/worker/worker.err"
get_pid() {
cat "$pid_file"
}
is_running() {
[ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1
}
case "$1" in
start)
if is_running; then
echo "Already started"
else
echo "Starting $name"
cd /var/lib/worker
. venv/bin/activate
. /etc/profile.d/worker.sh
python run.py >> "$stdout_log" 2>> "$stderr_log" &
echo $! > "$pid_file"
if ! is_running; then
echo "Unable to start, see $stdout_log and $stderr_log"
exit 1
fi
echo "$name running"
fi
Run Code Online (Sandbox Code Playgroud)
我在这条线上遇到了问题:
python run.py >> "$stdout_log" …Run Code Online (Sandbox Code Playgroud) 我正在玩亚马逊Rekognition.我找到了一个非常好/容易的库来从我的网络摄像头拍摄图像,其工作方式如下:
BufferedImage bufImg = webcam.getImage();
Run Code Online (Sandbox Code Playgroud)
我正在尝试将其转换BufferedImage为a com.amazonaws.services.rekognition.model.Image,这是必须提交给Rekognition库的内容.这就是我正在做的事情:
byte[] imgBytes = ((DataBufferByte) bufImg.getData().getDataBuffer()).getData();
ByteBuffer byteBuffer = ByteBuffer.wrap(imgBytes);
return new Image().withBytes(byteBuffer);
Run Code Online (Sandbox Code Playgroud)
但是当我尝试用Rekognition做一些API调用时Image,我得到一个例外:
com.amazonaws.services.rekognition.model.InvalidImageFormatException: Invalid image encoding (Service: AmazonRekognition; Status Code: 400; Error Code: InvalidImageFormatException; Request ID: X)
Run Code Online (Sandbox Code Playgroud)
该文档指出了Java SDK会自动使用Base64编码的字节数.万一发生了一些奇怪的事情,我在转换前尝试了base64编码字节:
imgBytes = Base64.getEncoder().encode(imgBytes);
Run Code Online (Sandbox Code Playgroud)
但是,同样的例外随之而来.
有任何想法吗?:)
是否可以根据其他条件使用不同的循环条件?
例如
boolean isDfa = true;
Run Code Online (Sandbox Code Playgroud)
如果isDfa是true,我希望while循环的条件是:
while(!s.hasAllTransitions())
Run Code Online (Sandbox Code Playgroud)
否则,如果isDfa是false,我希望while循环的条件是:
while(!input.equals("next"))
Run Code Online (Sandbox Code Playgroud)
使用两个独立的循环是实现这一目标的唯一方法吗?
我知道该before_request()功能是在执行附加到路由的功能之前执行的。
我的代码检查用户是否已登录该before_request()函数,如果不是,则将其重定向到索引页面。但是,重定向不起作用。这是我的代码:
@app.before_request
def before_request():
if(
(
request.endpoint != 'index' or
request.endpoint != 'home' or
request.endpoint != ''
)
and 'logged_in' not in session
):
print("NOT LOGGED IN")
redirect(url_for('index'))
Run Code Online (Sandbox Code Playgroud)
这会在终端中显示“ NO LOGGED IN”,但不会重定向。如何正确重定向?
python ×7
flask ×4
java ×3
bash ×2
sqlalchemy ×2
init ×1
linux ×1
long-polling ×1
runtime.exec ×1