我需要不断访问服务器以获取金融工具的实时数据.价格不断变化所以我需要每0.5秒申请新价格.经纪人的REST API让我这样做,但是,我注意到连接到服务器时有一些延迟.我只是注意到他们也有websocket API.根据我的阅读,他们都有一些利弊.但是对于我想要做的事情,因为速度在这里特别重要,如果您推荐使用哪种API?websocket真的更快吗?
谢谢!
假设我有一个线程和程序的主要部分.因为GIL,一个线程应该在正确的时间(而不是同时)工作?但是,如果其中一个线程是无限循环(或两者都是这样)呢?
这两个过程会并行运行吗?
def test():
while True:
print "hello"
def test2():
while True:
print "hi"
def start_thread():
try:
thread.start_new_thread( test2,() )
except:
print "Error: Unable to start thread"
start_thread()
test()
Run Code Online (Sandbox Code Playgroud) 我需要使用popen打开一个子进程,该进程将不断询问用户输入...主进程需要通过管道发送该数据.
这是我的第一次尝试:
FILE *in;
char buff[1024];
if(!(in = popen("cd FIX/fix2/src; java -cp .:./* com.fix.bot", "w"))){
return 1;
}
while(1){
char buffer[] = { 'x' };
fwrite(buffer, sizeof(char), sizeof(buffer), in);
cout << "Wrote!" << endl;
usleep(1000000);
}
Run Code Online (Sandbox Code Playgroud)
但是数据没有发送!我需要用pclose()关闭管道,以便将数据写入进程.如何在不必每次都关闭管道的情况下确保写入数据?
我正在使用 selenium + python,在 python 上使用隐式等待和 try/except 代码来捕获错误。但是我一直注意到,如果浏览器崩溃(假设用户在程序执行期间关闭浏览器),我的 python 程序将挂起,并且发生这种情况时隐式等待的超时似乎不起作用。下面的过程将永远停留在那里。
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium import webdriver
import datetime
import time
import sys
import os
def open_browser():
print "Opening web page..."
driver = webdriver.Chrome()
driver.implicitly_wait(1)
#driver.set_page_load_timeout(30)
return driver
driver = open_browser() # Opens web browser
# LET'S SAY I CLOSE THE BROWSER RIGHT HERE!
# IF I CLOSE THE PROCESS HERE, THE PROGRAM WILL HANG …Run Code Online (Sandbox Code Playgroud) 我下载了一个用java编写的示例代码,该代码包含多个jar文件和java文件.我不是Java程序员,所以我很难编译代码.这是我的尝试:
javac -classpath lib/*.jar src/*.java
Run Code Online (Sandbox Code Playgroud)
然而,这就是我得到的:
javac: invalid flag: lib/dom4j-1.6.1.jar
Usage: javac <options> <source files>
use -help for a list of possible options
Run Code Online (Sandbox Code Playgroud)
我的方法有什么问题,如何编译代码?ALl jar文件位于lib文件夹中,而java文件位于src文件夹中.
我正在尝试抓取页面上 div 内找到的表格。
到目前为止,基本上这是我的尝试:
# NOTE: Download the chromedriver driver
# Then move exe file on C:\Python27\Scripts
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
import sys
driver = webdriver.Chrome()
driver.implicitly_wait(10)
URL_start = "http://www.google.us/trends/explore?"
date = '&date=today%203-m' # Last 90 days
location = "&geo=US"
symbol = sys.argv[1]
query = 'q='+symbol
URL = URL_start+query+date+location
driver.get(URL)
table = driver.find_element_by_xpath('//div[@class="line-chart"]/table/tbody')
print table.text
Run Code Online (Sandbox Code Playgroud)
如果我运行脚本,并使用“stackoverflow”这样的参数,我应该能够抓取这个网站:https://www.google.us/trends/explore ?date=today%203-m&geo=US&q=stackoverflow
显然我的 xpath …
因此,与数据相关的标准操作之一是对其进行归一化并将其标准化,以使其具有均值0且标准偏差为1的正态分布数据,对吗?但是,如果数据不是正态分布的怎么办?
另外,所需的输出是否也必须正态分布?如果我希望前馈网络在两个类别(-1和1)之间进行分类,那将不可能标准化为均值0和std为1的正态分布吗?
前馈网是非参数的吧?因此,如果确实如此,对数据进行标准化处理是否仍然很重要?为何人们对此予以认同呢?
statistics normal-distribution machine-learning normalization neural-network
我有一个数据库,其中包含日期格式为:“ 2015-10-20 22:24:46”。我需要将这些日期转换为UNIX时间戳(UTC),最简单的方法是使用Python?