小编use*_*451的帖子

空闲PostgreSQL连接是否有超时?

1 S postgres  5038   876  0  80   0 - 11962 sk_wai 09:57 ?        00:00:00 postgres: postgres my_app ::1(45035) idle                                                                                 
1 S postgres  9796   876  0  80   0 - 11964 sk_wai 11:01 ?        00:00:00 postgres: postgres my_app ::1(43084) idle             
Run Code Online (Sandbox Code Playgroud)

我看到了很多.我们正在尝试修复连接泄漏.但与此同时,我们希望为这些空闲连接设置超时,最长可达5分钟.

postgresql database-connection

79
推荐指数
5
解决办法
14万
查看次数

Popen错误:[Errno 2]没有这样的文件或目录

我有一些自定义命令.

# works 
subprocess.Popen(['python'], stdout=subprocess.PIPE)
Run Code Online (Sandbox Code Playgroud)

但是,如果我有自己的系统命令deactivate,我会得到那个错误

Traceback (most recent call last):
  File "runner2.py", line 21, in <module>
    main() 
  File "runner2.py", line 18, in main
    subprocess.Popen(['deactivate',], stdout=subprocess.PIPE)
  File "/usr/lib/python2.6/subprocess.py", line 633, in __init__
    errread, errwrite)
  File "/usr/lib/python2.6/subprocess.py", line 1139, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
Run Code Online (Sandbox Code Playgroud)

更别说我需要在我的沙箱virtualenv下执行此操作.

python subprocess popen

45
推荐指数
3
解决办法
6万
查看次数

SQLAlchemy布尔值为None

我在Pyramid应用程序中有这个表

class User(Base):
    __tablename__ = 'users'
    id = Column(Integer, primary_key=True)
    .....
    is_active = Column(Boolean, unique=False)
    def __init__(self, name, raw_password):
        is_active = True
Run Code Online (Sandbox Code Playgroud)

当我做我的测试时,它说is_active是没有.

def test_register_user(self):
    user = User('user1', '1234')
    self.sess.add(user)
    self.sess.flush()

    #print user
    #self.assertTrue(user.is_active, True)
    user_db_record = self.sess.query(User).filter_by(name=user.name).first()
    self.assertEqual(user_db_record.is_active, True)
Run Code Online (Sandbox Code Playgroud)

从我的集成日志中,我看到在创建行时,is_active将其设置为None.为什么?

python sqlalchemy pyramid

28
推荐指数
3
解决办法
3万
查看次数

如何使用SSE执行8 x 8矩阵运算?

我最初的尝试看起来像这样(假设我们想要成倍增加)

  __m128 mat[n]; /* rows */
  __m128 vec[n] = {1,1,1,1};
  float outvector[n];
   for (int row=0;row<n;row++) {
       for(int k =3; k < 8; k = k+ 4)
       {
           __m128 mrow = mat[k];
           __m128 v = vec[row];
           __m128 sum = _mm_mul_ps(mrow,v);
           sum= _mm_hadd_ps(sum,sum); /* adds adjacent-two floats */
       }
           _mm_store_ss(&outvector[row],_mm_hadd_ps(sum,sum));
 }
Run Code Online (Sandbox Code Playgroud)

但这显然不起作用.我该如何处理?

我应该一次加载4个....

另一个问题是:如果我的数组很大(比如说n = 1000),我怎么能让它16字节对齐?这甚至可能吗?

c++ sse intrinsics

7
推荐指数
1
解决办法
866
查看次数

scanf第二次不会要求输入

#include "stdio.h"

int main(void)
{

     int order, nextp, N=3;
     char cont;
     nextp = 0;
     printf("\nShould we continue (y or n): ");
     scanf("%c", &cont);
     if (cont != 'y') return;
     for(; nextp < N; nextp++)
     {
        printf("Enter order number: ");
        scanf("%d", &order);
        printf("you have entered %d\n", order);
        printf("okay now continue with cont\n");


        printf("enter cont y or n: ");
        scanf("%c", &cont);
        if (cont != 'y')
        {
            printf("\nnot equal to y\n");
            break;
        }
        printf("after intepreting t[0]");
      }

   return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出看起来像这样

Should we continue …
Run Code Online (Sandbox Code Playgroud)

c scanf

6
推荐指数
2
解决办法
7586
查看次数

如何在django中获取密码?

我有一个python库,我为其他东西写了.所以我导入它在Django中使用,我面临的问题是如何获取密码.

mycustom_lib_function(username, password)
Run Code Online (Sandbox Code Playgroud)

username 我可以通过 request.user

但是,我不知道如何获取密码.有人能帮我吗?谢谢.

django

4
推荐指数
3
解决办法
2万
查看次数

我应该使用request.POST或form.cleaned_data中的文本

这可能听起来像一个微不足道的问题,但这对我来说是一场战斗.

对于表单和点击提交,是否应该使用form.cleaned_data访问表单数据或查找request.POST

人们通常唯一要做的request.POST就是查找提交按钮.但是如果我创建一个提交按钮作为一个小部件,我也可以在form.cleaned_data中查找它.问题是,其他表格数据呢?它们也可以查找request.POST.

谢谢.

django django-forms django-views

4
推荐指数
2
解决办法
3257
查看次数

字母,短划线,下划线,数字和空格的正则表达式

这是我的尝试

def matcher(ex):
    if re.match(r'^[\w|\d][A-Za-z0-9_-]+$', ex):
        print 'yes'
Run Code Online (Sandbox Code Playgroud)

我的目标是仅匹配满足以下所有内容的提交

  1. 仅以字母或数字开头,并且
  2. 只允许使用字母,空格,短划线,下划线和数字
  3. 所有结束空格都被剥离

在我的正则表达式中,matcher('__')被认为是有效的.如何修改以实现我真正想要的东西?我相信\w还包括下划线.但是matcher('_')不匹配......

python regex

2
推荐指数
1
解决办法
1万
查看次数

python模块驻留在名称中包含短划线字符的存储库中

我知道模块的名称不应该有破折号.

这是我的存储库结构

my-repo-name/
     src/ 
     tests/
        __init__.py
        tests.py
     fab/
        __init__.py
        fabfile.py

     README.rst
     __init__.py
Run Code Online (Sandbox Code Playgroud)

在我的测试中,我需要导入fabfile.py来运行测试.但由于名称有破折号,我不能做from my-module-name.fab.fabfile import X,Y,Z或相对导入,因为它是非包装.

任何建议如何在不乱砍__import__(...)或添加到sys路径的情况下执行此操作?我应该添加另一个目录吗?

python package

2
推荐指数
1
解决办法
3074
查看次数

我们需要setTimeout进行短轮询吗?

如果我想实现这样的短轮询:

function firstCall(){
   $.ajax({
     ...
     success: function(response){
         if (response.OK == "OK"){
              secondCall();
         }else{
            firstCall();
         }
     }
  });

}
Run Code Online (Sandbox Code Playgroud)

这还够吗?或者我真的需要用firstCall()in else子句包围setTimeout吗?谢谢

javascript jquery polling

2
推荐指数
1
解决办法
922
查看次数