首页 \ 问答 \ 线程从另一个线程中断(Thread interruption from another thread)

线程从另一个线程中断(Thread interruption from another thread)

我使用这样的东西创建了9个线程(所有线程都会处理无限循环)

void printStr();

thread func_thread(printStr);
void printStr() {

    while (true) {
        cout << "1\n";
        this_thread::sleep_for(chrono::seconds(1));
    }

}

我还创建了第10个线程来控制它们。 我将如何阻止或杀死我的第10条线中的任何一条? 或者请提出另一种机制。


I'm creating 9 threads using something like this (all threads will process infinity loop)

void printStr();

thread func_thread(printStr);
void printStr() {

    while (true) {
        cout << "1\n";
        this_thread::sleep_for(chrono::seconds(1));
    }

}

I also create 10th thread to control them. How would I stop or kill any of this 9 threads from my 10th? Or suggest another mechanism please.


原文:https://stackoverflow.com/questions/23188275
更新时间:2023-03-27 14:03

最满意答案

这里的行是说将Sender列作为源节点,将Recipient列作为Target,并将time添加为edge属性 。 因此,您只在Sender和Recipient之间创建单个(定向)边,并且只将最后一行的时间添加为边的属性。

email = nx.from_pandas_dataframe(email_df, '#Sender', 'Recipient', edge_attr = 'time')

您只能为一对节点定义一条边 - 您可以在构建网络之前对数据框进行分组,并将计数用作边的权重,

edge_groups = email_df.groupby(["#Sender", "Recipient"], as_index=False).count().rename(columns={"time":"weight"})
email = nx.from_pandas_dataframe(edge_groups, '#Sender', 'Recipient', edge_attr = 'weight')

Your line here is saying to take the Sender column as the source node, the Recipient column as the Target and add the time as edge attributes. So you are only creating a single (directed) edge between Sender and Recipient, and only the time of the last row will be added as an attribute of the edge.

email = nx.from_pandas_dataframe(email_df, '#Sender', 'Recipient', edge_attr = 'time')

You can only have one edge defined for a pair of nodes - you could group the dataframe before constructing your network and use the count as the weights for the edges,

edge_groups = email_df.groupby(["#Sender", "Recipient"], as_index=False).count().rename(columns={"time":"weight"})
email = nx.from_pandas_dataframe(edge_groups, '#Sender', 'Recipient', edge_attr = 'weight')

相关问答

更多
  • 假设数据框架: df = pd.DataFrame({'a':['5','10'], 'b':['9','7']}) 目前的数据类型: In [391]: df.dtypes Out[391]: a object b object 将整个df列转换为数字: df = df.apply(pd.to_numeric) 结果: In [393]: df.dtypes Out[393]: a int64 b int64 仅将选择列转换为数字: In [396]: df = pd. ...
  • 这意味着你有一个额外的空间。 虽然pd.to_datetime非常擅长解析日期而通常没有指定任何格式,但是当您实际指定格式时,它必须完全匹配。 您可以通过添加.str.strip()来解决您的问题,以在转换之前删除额外的空格。 import pandas as pd df['Time stamp'] = pd.to_datetime(df['Time stamp'].str.strip(), format='%d/%m/%Y') 或者,您可以使用dayfirst=True参数来利用其解析各种格式的日期的功 ...
  • 如果您将边和节点都作为列表,那么在networkx中构建图表非常简单。 鉴于您在构建图形对象时出现问题,最好的诊断方法是逐步完成networkx中的图形构建: import networkx as NX import string import random G = NX.Graph() # initialize the graph # just generate some synthetic data for the nodes and edges: my_nodes = [ ch for ch ...
  • 这里的行是说将Sender列作为源节点,将Recipient列作为Target,并将time添加为edge属性 。 因此,您只在Sender和Recipient之间创建单个(定向)边,并且只将最后一行的时间添加为边的属性。 email = nx.from_pandas_dataframe(email_df, '#Sender', 'Recipient', edge_attr = 'time') 您只能为一对节点定义一条边 - 您可以在构建网络之前对数据框进行分组,并将计数用作边的权重, edge_grou ...
  • 本教程基于networkx的先前版本,其中g.edges()或g.edges(Data=True)会给你一个元组列表。 列表是可订阅的。 您正在运行的版本具有不同的输出, g.edges为您提供了一个EdgeView属性,而g.edges(data=True)是一个不可下标的EdgeDataView对象。 要回答你的问题,你可以这样做: list(g.edges(data=True))[0:5] 注意:对于g.nodes()也是如此:在它现在是一个list之前,它是一个NodeView属性而不是可下载的。 ...
  • 您可以使用g.loc选择isconfirm为0的所有行: In [90]: g.loc[:, 0] Out[90]: ID 0 0.827957 1 0.911111 2 0.944954 3 0.884956 4 0.931373 5 0.869048 6 0.941176 7 0.884615 8 0.901961 9 0.930693 Name: isconfirm, dtype: float64 [:, 0]表示索引的第二级中的值。 因 ...
  • 在数据帧上使用replace方法: import numpy as np df = DataFrame({ 'k1': ['na'] * 3 + ['two'] * 4, 'k2': [1, 'na', 2, 'na', 3, 4, 4]}) print df df = df.replace('na', np.nan) print df 我认为指出df.replace('na',np.nan)本身不起作用是有帮助的。 您必须将其分配回现有数据框。 Use the replace method on ...
  • 原因是图表是无向的。 igraph和networkx处理I - J平局和J - I networkx对待。 panda.intersection只会处理完全匹配(即数据帧A中的第1列与数据帧B中的第1列匹配,数据帧A中的第2列与数据帧B中的第3列匹配)。 library(igraph); library(dplyr) set.seed(1034) g1 <- sample_gnp(20, 0.25, directed = F) set.seed(1646) g2 <- sample_gnp(20, 0.25 ...
  • 一个更小的问题可能有助于获得答案。 (例如,你的x.py没有任何内容与x.py的问题相关) 为了帮助您入门,您可能会遇到一些名称空间重载(重命名相同的对象)。 在netxgui.py您import networkx as nx但稍后您会声明一个类nx(QtGui.QDialog) 。 在此之后你尝试调用nx.spring_layout() ,你可能想要从networkx而不是你的自定义nx类。 您尝试访问的结构可能存在于networkx Graph实例中但不存在于QDialog实例中? 通常,避免使用fro ...
  • 虽然您可以使用nx.non_edges()找到图中缺少边的位置,但该函数实际上并不返回可以分配数据的对象 - 毕竟逻辑图中不存在非边。 但是,您可以创建第二个图形,其中包含不在第一个图形中的所有边缘,然后将分数分配给第二个图形中的边缘。 import networkx as nx import numpy as np G1 = nx.MultiGraph() G1.add_edges_from([ ('1', '2'), ('1', '3'), ('1', '5'), ( ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。