Python Forum
Multithreading dynamically syncronism
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multithreading dynamically syncronism
#1
Hi there, I have n threads named as: E1, E2, E3, ... And additionally another m number os threads named as: C1, C2, C3, ... The (C ) type threads are dependent from 2*(E) type threads. I want to dynamically syncronize (C ) threads to start just when the dependents (E) are finished. All threads are started with know name and I have a dictionary with respective dependencies. I know I doing it wrong at (Condicoes[i][j]).join() on attached code. I tried to iterate with threadsList but I dont know how to recover the (E) threads names to compare with my dict conditons. My ListaThreadEntradas has this: [<Thread(E1, stopped daemon 18288)>, <Thread(E2, stopped daemon 11428)>, <Thread(E3, stopped daemon 1908)>, <Thread(E4, stopped daemon 3436)>] If I can get those En values I could compare with my dependency dictionary. Can anyone help me out, please?
 # -*- coding: utf-8 -*- #!/usr/bin/env python import time import json import threading #time delay funcion def demora(Tempo = 0): time.sleep(Tempo) print ("wait "+str(Tempo)+"s") #Json with all possible En. It will be dynamically assign. EntradasString = '{ "E1" : "1", "E2" : "2", "E3" : "3", "E4" : "4" }' Entradas = json.loads(EntradasString) #Dynamic allocation of threads. ListaThreadEntradas = [] for i in (Entradas): x = threading.Thread(target=demora, name=i, args=(int(Entradas[i]),), daemon=True) ListaThreadEntradas.append(x) x.start() #Condition depend on two E type theads.It will be dynamically assign ListaCondicoes = ' {"C1" : {"0": "E1", "1": "E2"} } ' Condicoes = json.loads(ListaCondicoes) def dependente(): inicio = time.time() for i in (Condicoes): for j in ( Condicoes[i] ): (Condicoes[i][j]).join() fim = time.time() - inicio print ("Took: " + str(fim) + "s") C1 = threading.Thread(target=dependente, name="C1", args=(), deamon=True) C1.start() 
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  multithreading Hanyx 4 1,282 Jul-29-2022, 07:28 AM
Last Post: Larz60+
Question Problems with variables in multithreading Wombaz 2 1,286 Mar-08-2022, 03:32 PM
Last Post: Wombaz
  Multithreading question amadeok 0 1,748 Oct-17-2020, 12:54 PM
Last Post: amadeok
  How can i add multithreading in this example WoodyWoodpecker1 3 2,451 Aug-11-2020, 05:30 PM
Last Post: deanhystad
  matplotlib multithreading catosp 0 2,908 Jul-03-2020, 09:33 AM
Last Post: catosp
  Locks in Multithreading Chuonon 0 1,819 Oct-03-2019, 04:16 PM
Last Post: Chuonon
  multithreading issue with output mr_byte31 4 3,148 Sep-11-2019, 12:04 PM
Last Post: stullis
  Multithreading alternative MartinV279 1 2,731 Aug-01-2019, 11:41 PM
Last Post: scidam
  using locks in multithreading in python3 srm 2 3,615 Jul-13-2019, 11:35 AM
Last Post: noisefloor
  Multithreading in a loop valtih 3 16,342 Aug-03-2017, 08:20 PM
Last Post: valtih

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020