当我试图运行我的代码时,它抛出这个Exception:
Exception in thread "main" org.apache.spark.SparkException: Could not parse Master URL:spark:http://localhost:18080
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
SparkConf conf = new SparkConf().setAppName("App_Name").setMaster("spark:http://localhost:18080").set("spark.ui.port","18080");
JavaStreamingContext ssc = new JavaStreamingContext(sc, new Duration(1000));
String[] filet=new String[]{"Obama","ISI"};
JavaReceiverInputDStream<Status> reciverStream=TwitterUtils.createStream(ssc,filet);
JavaDStream<String> statuses = reciverStream.map(new Function<Status, String>() {
public String call(Status status) { return status.getText(); }
}
);
ssc.start();
ssc.awaitTermination();}}
Run Code Online (Sandbox Code Playgroud)
知道如何解决这个问题?
正如我们在go中所知,当goroutine必须执行阻塞调用(例如系统调用)或通过cgo调用C库时,可能会创建一个线程.一些测试代码:
package main
import (
"io/ioutil"
"os"
"runtime"
"strconv"
)
func main() {
runtime.GOMAXPROCS(2)
data, err := ioutil.ReadFile("./55555.log")
if err != nil {
println(err)
return
}
for i := 0; i < 200; i++ {
go func(n int) {
for {
err := ioutil.WriteFile("testxxx"+strconv.Itoa(n), []byte(data), os.ModePerm)
if err != nil {
println(err)
break
}
}
}(i)
}
select {}
}
Run Code Online (Sandbox Code Playgroud)
当我运行它时,它没有创建很多线程.
? =99=[root /root]$ cat /proc/9616/status | grep -i thread
Threads: 5
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
以下代码运行完全正常:
package main
import (
"fmt"
)
func my_func(c chan int){
fmt.Println(<-c)
}
func main(){
c := make(chan int)
go my_func(c)
c<-3
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我改变
c<-3
Run Code Online (Sandbox Code Playgroud)
至
time.Sleep(time.Second)
c<-3
Run Code Online (Sandbox Code Playgroud)
我的代码没有执行.
我的直觉是main在my_func完成执行之前以某种方式返回,但似乎添加暂停应该没有任何效果.我完全迷失在这个简单的例子上,这里发生了什么?
我在我的表单中有一个多选输入,我试图在我的处理程序中获取所选值,但我不能,我怎么能得到这些值?
<form action="process" method="post">
<select id="new_data" name="new_data class="tag-select chzn-done" multiple="" style="display: none;">
<option value="1">111mm1</option>
<option value="2">222mm2</option>
<option value="3">012nx1</option>
</select>
</form>
Run Code Online (Sandbox Code Playgroud)
我的处理程序:
func myHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.FormValue("new_data")) // result-> []
fmt.Println(r.Form("new_data")) // result-> []
}
Run Code Online (Sandbox Code Playgroud)
表单序列化数据,从JS控制台中选择选项1和2:
>$('#myform').serialize()
>"new_data=1&new_data=2"
Run Code Online (Sandbox Code Playgroud) 我正在编写一个服务,必须将已执行命令的输出流式传输到父级和日志.当有一个漫长的过程时,问题是cmd.StdoutPipe给我一个最终的(字符串)结果.
是否可以给出正在发生的事情的部分输出,比如在shell中
func main() {
cmd := exec.Command("sh", "-c", "some long runnig task")
stdout, _ := cmd.StdoutPipe()
cmd.Start()
scanner := bufio.NewScanner(stdout)
for scanner.Scan() {
m := scanner.Text()
fmt.Println(m)
log.Printf(m)
}
cmd.Wait()
}
Run Code Online (Sandbox Code Playgroud)
PS只是输出将是:
cmd.Stdout = os.Stdout
Run Code Online (Sandbox Code Playgroud)
但就我而言,这还不够.
我想在3年前得到时间unix时间戳,我现在用它:
time.Now().Unix(() - 3 * 3600 * 24 * 365
Run Code Online (Sandbox Code Playgroud)
无论如何这都不准确(因为年份可能有366天).
我正在尝试使用"Go Go Programming Language"来学习Golang,并且我已经达到了关于切片的部分.他们在数组和切片之间进行比较,==因为可以将两个数组与两个切片不能进行比较.该文本如下:
"== operator for arrays of strings, it may be puzzling that slice
comparisons do not also work this way. There are two reasons why deep
equivalence is problematic. First, unlike array elements, the elements
of a slice are indirect, making it possible for a slice to contain
itself. Although there are ways to deal with such cases, none is
simple, efficient, and most importantly, obvious."
Run Code Online (Sandbox Code Playgroud)
由于元素是间接的,因此切片可能包含自身的含义是什么意思?
我有一个用go编写的网络服务器,我正在提供来自不同来源(本地,其他服务器,S3)的一些音频文件.我想为这些文件启用部分内容,以便HTML音频标签能够搜索和循环.
我怎么能得到这个?我知道http包ServeContent函数可以做到这一点,但我怎么能通过自己提供文件来实现呢?我需要在没有这个的情况下这样做,以便我可以使用相同的处理程序提供来自不同来源的文件.
当我定义一个自定义类型时,似乎底层类型的类型对我是否可以将其传递给函数或我需要转换它有所不同.
问题是:
为什么RuneFunc和StringMap有效,但不是Integer?
https://play.golang.org/p/buKNkrg5y-
package main
type RuneFunc func(rune) rune
type Integer int
type StringMap map[string]string
func main() {
//m := make(StringMap)
//mf(m)
var i Integer = 5
nf(i)
//var f func(rune) rune
//ff(f)
}
func mf(i map[string]string) {
}
func ff(i func(rune)rune) {
}
func nf(i int) {
}
Run Code Online (Sandbox Code Playgroud)
在这里,当我运行这个函数调用nf与Integer它抱怨,虽然int是基础类型.但是当我打电话mf或ff他们成功运行时.
我正在使用 Go 1.13.1,截至今天最新。
我正在尝试go get从 GitHub 中完全删除我安装的软件包。本go clean -i <PACKAGE_NAME>似乎没有工作,因为有文件通过传播,至少,这些目录:
~/go/pkg/mod/github.com/<PACKAGE_NAME>
~/go/pkg/mod/cache/download/github.com/<PACKAGE_NAME>
~/go/pkg/mod/cache/download/sumdb/sum.golang.org/lookup/github.com/<PACKAGE_NAME>
Run Code Online (Sandbox Code Playgroud)
有没有办法在不手动删除所有内容的情况下清理所有内容?