小编Ama*_*pta的帖子

Python:多处理和请求

以下是我运行的代码片段,用于使用多处理并行触发HTTP请求.在控制台上运行后,它会挂起"requests.get(url)"并且既不会前进也不会抛出错误.

def echo_100(q):
    ...
    print "before"
    r = requests.get(url)
    print "after"
    ...
    q.put(r)

q = multiprocessing.Queue()
p = multiprocessing.Process(target=echo_100,args=(q))
p.start()
p.join()
resp = q.get()
Run Code Online (Sandbox Code Playgroud)

python python-2.7

5
推荐指数
2
解决办法
1613
查看次数

Firefox无法打开子域

我有一个nodejs应用程序,表示正在运行的后端localhost.我有与之相关的子域名user1.localhost.这些子域名在Chrome中打开,但Firefox会引发Server Not Found错误.

Firefox是否需要一些配置才能允许子域名?

firefox google-chrome node.js express

5
推荐指数
1
解决办法
1241
查看次数

量角器elementExplorer

我正在尝试使用量角器elementExplorer并且不确定为什么我不能这样做(我正在使用Mac).

根据文档 - http://angular.github.io/protractor/#/debugging我要去量角器目录(使用/ local/bin)并输入

node ./bin/elementexplorer.js
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

module.js:340
throw err;
      ^
Error: Cannot find module '/usr/local/bin/bin/elementexplorer.js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
Run Code Online (Sandbox Code Playgroud)

任何帮助?谢谢.

debugging node.js angularjs selenium-webdriver protractor

4
推荐指数
1
解决办法
3124
查看次数

客户端渲染React

我是 React(Angular 背景)新手,并尝试使用 React 进行客户端渲染。以下是express应用程序发送的index.html:

<html>
    <head>
        <title>My Web</title>
        <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.1/react.min.js"></script>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.1/react-dom.min.js"></script>
        <script type="text/javascript" src="/static/src/js/firstComponent.js"></script>
    </head>

    <body id="mainBody">
    </body>

</html>
Run Code Online (Sandbox Code Playgroud)

这是反应组件文件(firstComponent.js):

var FirstComponent = React.createClass({
    'render': function(){
        return <h1> Hello</h1>;
    }
});

ReactDOM.render(<FirstComponent />, document.getElementById('mainBody'));
Run Code Online (Sandbox Code Playgroud)

但在加载页面时,反应似乎不起作用。这里有什么问题吗?

javascript reactjs

3
推荐指数
1
解决办法
5150
查看次数

在Selenium webdriver.switchto()中,"relative = top"会产生错误吗?

我正在使用Selenium WebDriver(v2.2)"切换"到"顶部"框架,如下所示:

webdriver.SwitchTo().Frame("relative=top");
Run Code Online (Sandbox Code Playgroud)

这会生成错误消息:

Unable to locate frame: relative=top
Run Code Online (Sandbox Code Playgroud)

这可能是因为我使用的页面没有框架吗?

编辑

不幸的是,涉及窗口切换的两种解决方案均

webdriver.SwitchTo().Window(winHandle);
webdriver.SwitchTo().DefaultContent();
Run Code Online (Sandbox Code Playgroud)

严格来说,实际上,他们并没有失败.但是,这就是问题所在:假设我在一帧内获取一个IWebElement.这是代码大致的样子:

descend-into-the-frame
grab-the-element
ascend-out-of-the-frame-to-the-top
use-the-element
Run Code Online (Sandbox Code Playgroud)

当我使用-the-element时,我得到一个"缓存中不存在元素"异常.这是因为从框架上升到顶部会切换窗口,从而清除缓存.真烦人 不过我找到了一个解决方法:

ascend-out-of-the-frame-to-the-top
descend-into-the-frame
grab-the-element
use-the-element
Run Code Online (Sandbox Code Playgroud)

这仍然意味着我必须注意元素不在缓存的情况.但至少只要我在拿取元素后立即使用它,我就可以了.

感谢大家的帮助!

selenium webdriver selenium-webdriver

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

为什么JSON.parse无法检测参数是否已经是JSON格式

正如我们所知,JSON.parse解析了stringified JSON,但是如果一个变量已经存在JSON并且您尝试执行JSON.parse该操作则会抛出错误:

> a
[]
> a = JSON.parse(a)
SyntaxError: Unexpected end of input
    at Object.parse (native)
    at repl:1:10
    at REPLServer.defaultEval (repl.js:132:27)
    at bound (domain.js:254:14)
    at REPLServer.runBound [as eval] (domain.js:267:12)
    at REPLServer.<anonymous> (repl.js:279:12)
    at REPLServer.emit (events.js:107:17)
    at REPLServer.Interface._onLine (readline.js:214:10)
    at REPLServer.Interface._line (readline.js:553:8)
    at REPLServer.Interface._ttyWrite (readline.js:830:14)
Run Code Online (Sandbox Code Playgroud)

为什么不能JSON.parse验证参数已经是a JSON object并且在这种情况下什么都不做而不是抛出错误?

javascript json

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

HTML5:没有“src”属性的视频元素

我正在使用 webrtc 库之一来显示视频并将收到的流附加到视频元素。但是当我检查视频元素时,src属性丢失。

<video autoplay="" id="EKA-e2RERLzhCFy8AAEd" class="videoRoom"></video>
Run Code Online (Sandbox Code Playgroud)

我这里有几个问题:

  1. 元素是否可以video没有src属性?
  2. 如果可以的话,如何获取src该视频

html javascript html5-video

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

Redis:如何防止这种竞争状况

我有一个redis哈希值,其中一个字段的值为字符串化数组,每当用户注册一个事件时,

  1. 从redis获取此字符串化数组
  2. 在后端解析并在数组中添加用户的用户名
  3. stringify数组并存储回hash

如果两个用户在足够接近的时间注册,则存在潜在的竞争条件.

竞争条件可能是这样的,两个用户从redis获得相同的字符串化数组,然后他们修改,只有一个更新将发生,因为一个将被其他人覆盖.

有没有办法防止像SQL中的事务这样的竞争条件.我已经阅读过multi,但它不允许在服务器上的命令之间进行计算.

或者存储字符串化数组并存储为哈希字段是一个坏主意,我应该在redis上使用普通列表.

race-condition redis

0
推荐指数
1
解决办法
740
查看次数

Javascript:获取字符串的最后几个字符

如果我们将字符串存储在变量中,这是一个微不足道的问题。但出于好奇,我需要了解如何在不将字符串存储在变量中的情况下实现这一点?

//  To get first few characters of a string, we can do something like this:
var x = "amangupta".substring(0,7); //amangup

//  How to get last 7 characters
var x = "amangupta".substring(this.length - 7, this.length); // does not work, looking for similar approach

var str = "amangupta";
var x = str.substring(str.length - 7, str.length); // will work fine
Run Code Online (Sandbox Code Playgroud)

javascript string

0
推荐指数
1
解决办法
3533
查看次数