我正在python和扭曲的框架中创建一个聊天守护进程.我想知道是否必须删除我的函数中创建的每个变量,以便在连接多个用户时长期保存内存,或者这些变量是否自动清除?这是我的代码的精简版,以说明我的观点:
class Chat(LineOnlyReceiver):
LineOnlyReceiver.MAX_LENGTH = 500
def lineReceived(self, data):
self.sendMessage(data)
def sendMessage(self, data):
try:
message = data.split(None,1)[1]
except IndexError:
return
self.factory.sendAll(message)
#QUESTION : do i have to delete message and date??????????????????
del message
del data
class ChatFactory(Factory):
protocol = Chat
def __init__(self):
self.clients = []
def addClient(self, newclient):
self.clients.append(newclient)
def delClient(self, client):
self.clients.remove(client)
def sendAll(self, message):
for client in self.clients:
client.transport.write(message + "\n")
Run Code Online (Sandbox Code Playgroud) 当我尝试访问用户时显示错误#show page通过命名路由(http:// localhost:3000/profile /)...否则当我尝试使用标准URL访问它时我没有错误( HTTP://本地主机:3000 /用户/电流).如果我耙路线我的路线似乎是正确的,因为它适用于标准网址,我真的不知道为什么我得到无路由匹配错误.为什么当我甚至没有尝试访问它时为什么试图寻找行动'毁灭'的路线匹配?
Starcast::Application.routes.draw do
match "login" => 'user_sessions#new', :as => :login
match "logout" => 'user_sessions#destroy', :as => :logout
resources :user_sessions
match "profile" => 'users#show'
resources :users
resources :casters
resources :casts
resources :orders
root :to => "home#index"
end
Run Code Online (Sandbox Code Playgroud)
我得到的错误:
ActionView::Template::Error (No route matches {:action=>"edit", :controller=>"users"}):
1: <% title "Welcome #{@user.username}" %>
2:
3: <%= link_to "Edit your profil", edit_user_path %>
4:
5: <% has_role? :caster do %>
6: <% if @user.caster %>
app/views/users/show.html.erb:3:in `_app_views_users_show_html_erb___2116234531537545622_2170017780__3613739707062673465'
Run Code Online (Sandbox Code Playgroud) 我编写了一个node.js应用程序,当执行时需要从进程返回CWD才能读取磁盘上的文件.
当我直接使用实际应用程序目录中的节点启动应用程序时...
#!sh
node app.js
Run Code Online (Sandbox Code Playgroud)
一切正常,"process.cwd()"返回好路径.但是当脚本以upstart启动时,甚至直接与其他目录中的节点"process.cwd()"一起返回"/",在upstart的情况下,以及来自巫婆的任何目录,我直接用节点启动我的应用程序.所以process.cwd()似乎从执行命令输出目录.为什么?该怎么办?
数据字符串通过套接字连接接收.当收到动作变量='IDENTIFY'的第一个例子时,它可以工作.但是当收到动作变量='MSG'的第二个例子时,它不会进行比较.
最奇怪的是,当我使用Telnet而不是我的套接字客户端时,两者都是成功比较的.但字符串是相同的...字符串是否有可能以相同的方式编码?我怎么知道?
数据示例:
data = 'IDENTIFY 54143'
or
data = 'MSG allo'
action = data.partition(' ')[0]
if action == "MSG":
self.sendMessage(data)
elif action == "IDENTIFY":
self.sendIdentify(data)
else:
print "false"
Run Code Online (Sandbox Code Playgroud) 我尝试在我的应用程序中使用节点require()包含.js文件,但是得到此错误.任何的想法?
a.js:
function a() {
this.a = 'a';
}
Run Code Online (Sandbox Code Playgroud)
节点应用:
require("./a.js");
var test = new a();
Run Code Online (Sandbox Code Playgroud)
错误:
/Users/.../app.js:14
var test = new a()
^
ReferenceError: a is not defined
Run Code Online (Sandbox Code Playgroud) 这是关于js中的oop的一些问题(下面的代码中的问题).
<html>
<script>
function A(){
a = 'a - private FROM A()';
this.a = 'a - public FROM A()';
this.get_a = function(){
return a;
}
}
function B(){
this.b = 'b - private FROM B()';
this.a = 'a - public FROM B() ';
}
C.prototype = new A();
C.prototype = new B();
C.prototype.constructor = C;
function C() {
A.call(this);
B.call(this);
}
var c = new C();
//I've read paper about oop in Javacscript but they never talk
//(the ones have …Run Code Online (Sandbox Code Playgroud)