调用函数时出现以下错误send_message.
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
self.run()
File "/usr/lib/python3.4/threading.py", line 868, in run
self._target(*self._args, **self._kwargs)
File "/home/joffe/Documents/discord/irc/ircbot.py", line 44, in get_message
mydiscord.send_message(line[1])
File "/home/joffe/Documents/discord/irc/mydiscord.py", line 37, in send_message
client.loop.run_until_complete(client.send_message(SERVER,message))
File "/usr/lib/python3.4/asyncio/base_events.py", line 331, in run_until_complete
self.run_forever()
File "/usr/lib/python3.4/asyncio/base_events.py", line 296, in run_forever
raise RuntimeError('Event loop is running.')
RuntimeError: Event loop is running.
Run Code Online (Sandbox Code Playgroud)
我的功能send_message接收消息并将其发送到不和谐频道.该函数是从一个在线程中运行的函数调用的.客户端对象在主线程中创建.
def send_message(message):
print(str.encode("Message to discord: " + message))
client.loop.run_until_complete(client.send_message(SERVER,message))
Run Code Online (Sandbox Code Playgroud) 我正在编写一个测试,以查看从流中读取时不同缓冲区大小的时间差异。与其在代码中的任何地方更改缓冲区大小,不如让一些预处理器为我做这件事,这样我只需要在一个地方更改值。
我正在考虑的一个例子是编写 C 宏define BUFFER 1024,并在创建数组时使用它来定义大小。
我试图建立一个尽可能快的队列,并计划将其排成一列,这样我就可以使用许多功能,并且从一开始就了解所有内容。这意味着我将永远不会尝试添加比分配了数组更多的元素。
即使我只实现了我需要的东西,但是当我完成(〜2000)次读写操作时,我仍然迷失在内置队列中。
我很好奇是什么使内置队列比我的裸露队列快?
如您所见,队列基于圆形数组,因此我无需移动任何元素。我还只是覆盖数据,而不是创建新节点来节省时间。(即使在我的测试中,也没有太大的区别。)
class Queue<T> {
private class Node {
public T data;
public Node(T data) {
this.data = data;
}
public Node() {
}
}
Node[] nodes;
int current;
int emptySpot;
public Queue(int size) {
nodes = new Node[size];
for (int i = 0; i < size; i++) {
nodes[i] = new Node();
}
this.current = 0;
this.emptySpot = 0;
}
public void Enqueue(T value){
nodes[emptySpot].data = value;
emptySpot++;
if (emptySpot >= nodes.Length) {
emptySpot = 0;
} …Run Code Online (Sandbox Code Playgroud) 我有一个使用voce.h 的程序,而voce.h 又使用jvm。
我已经包含了所有必要的 java 文件并链接到 libjvm.so,所以我现在没有收到编译器错误,但是当我运行程序时,我收到错误消息:
error while loading shared libraries: libjvm.so: cannot open shared object file: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我尝试了导出 LD_LIBRARY_PATH 部分但没有成功。
The link to libjvm.so
/usr/java/jre1.8.0_65/lib/amd64/server/libjvm.so
The path to include files
/usr/java/jdk1.8.0_65/include
/usr/java/jdk1.8.0_65/include/linux
Run Code Online (Sandbox Code Playgroud)
我使用 code::blocks 作为 IDE。
我编写了以下代码来解析字符串以获取其中编码的整数,并使用match. 如果我得到一个Err(e)我想打印出错误e,并返回一个默认值。
return match t.parse::<usize>() {
Ok(n) => n,
Err(e) => {
println!("Couldn't parse the value for gateway_threads {}", e);
// Return two as a default value
return 2;
},
};
Run Code Online (Sandbox Code Playgroud)
然而,该代码无法编译,因为它需要类型()但得到一个整数:
return match t.parse::<usize>() {
Ok(n) => n,
Err(e) => {
println!("Couldn't parse the value for gateway_threads {}", e);
// Return two as a default value
return 2;
},
};
Run Code Online (Sandbox Code Playgroud)
如果我删除默认值的返回,我会收到错误expected usize but got `()`:
error[E0308]: mismatched types
--> …Run Code Online (Sandbox Code Playgroud) 我收到一个错误'RentedMediaItem不是一个类型.Hoverever它说当我使用类作为参数而不是当我使用它作为对象时.
inventory.h我收到错误.
#ifndef INVENTORY_H
#define INVENTORY_H
#include <QString>
#include "rentedmediaitem.h"
#include "historypurchase.h"
#include "supportticket.h"
class RentedMediaItem;
class Inventory
{
private:
RentedMediaItem * RentedMediaItem; // No error
MediaItem** mediaItems;
HistoryPurchase* historyPurchase;
SupportTicket* tickets;
public:
Inventory();//Not implemented
void supportTicket(QString Text); //Not implemented
QString* getAllSupportTickets(); //Not implemented
QString supportTicket(int index); //Not implemented
void mediaItem(int index); //Not implemented
QString* getAllRentedMediaItems(); //Not implemented
HistoryPurchase* getPurchaseHistory(); //Not implemented
void useMedia(int index); //Not implemented
void addMediaItem(RentedMediaItem* rentedMediaItem); //ERROR
};
#endif // INVENTORY_H
Run Code Online (Sandbox Code Playgroud)
rentedmediaitem.h我在其中声明了RentedMediaItem类.
#ifndef RENTEDMEDIAITEM_H
#define RENTEDMEDIAITEM_H …Run Code Online (Sandbox Code Playgroud)