线程无限循环

时间:2018-11-09 03:58:02

标签: python python-3.x multithreading infinite-loop python-multithreading

private float HorizontalTileHeightMultiplier = 2;

private void menuItem1_Click(object sender, EventArgs e)
{
    TileHorizontal()
}

private void TileHorizontal()
{
    int OpenedForms = Application.OpenForms.Count - 1;
    if (OpenedForms < 2) return;

    int StartLocation = 0;
    int ChildrenHeight = 
        (int)((this.ClientSize.Height / OpenedForms) * HorizontalTileHeightMultiplier);

    List<Form> children = this.MdiChildren.OrderBy(f => f.Name).ToList();
    foreach (Form child in children)
    {
        child.Size = new Size(this.ClientSize.Width - SystemInformation.VerticalScrollBarWidth - 4, ChildrenHeight);
        child.Location = new Point(0, StartLocation);
        StartLocation += ChildrenHeight;
    }
}

以上代码仅显示def check_incoming_messages_to_client(incoming_chat_messages,uri_str, kill_threads_subscript): global kill_threads messaging = Pyro4.Proxy(uri_str) while(TRUE): if(messaging.get_connection() == 'yes'): msg = messaging.read_messages_to_client() if (msg): incoming_chat_messages.insert(END, msg) if(kill_threads[kill_threads_subscript]): print('break loop') break print('start') t1 = Thread(target=check_incoming_messages_to_client(incoming_chat_messages[length-1],uri_str, kill_threads_subscript)) t1.setDaemon(True) t1.start() print('end') ,而不显示start。这意味着它陷入了无限循环,这一定不是因为它是线程化的。我该如何解决?

1 个答案:

答案 0 :(得分:1)

Thread(target=check_incoming_messages_to_client(incoming_chat_messages[length-1],uri_str, kill_threads_subscript)) 调用函数,然后将结果作为target传递(除非因为它永远不会结束,所以永远不会实现,甚至您也不会构造{{ 1}})。

您要分别传递函数未调用Thread,以便 thread 在运行时调用它,而不是在运行之前运行的主线程工作线程甚至启动:

args