Bottom Page

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() 
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Locks in Multithreading Chuonon 0 168 Oct-03-2019, 04:16 PM
Last Post: Chuonon
  multithreading issue with output mr_byte31 4 307 Sep-11-2019, 12:04 PM
Last Post: stullis
  Multithreading alternative MartinV279 1 293 Aug-01-2019, 11:41 PM
Last Post: scidam
  using locks in multithreading in python3 srm 2 356 Jul-13-2019, 11:35 AM
Last Post: noisefloor
  Multithreading in a loop valtih 3 8,729 Aug-03-2017, 08:20 PM
Last Post: valtih
  Multithreading with ssh connection harusin 6 2,445 Jul-10-2017, 11:40 AM
Last Post: harusin

Forum Jump:


Users browsing this thread: 1 Guest(s)