Running dependent threads in parallel in python

Asked

Viewed 37 times

-5

I’m trying to run 2 threads simultaneously in my Python program:

from threading import Thread
import manipulateData
import stream

processo1 = Thread(stream.main())
print(processo1)
processo2 = Thread(manipulateData.main())
print(processo2)

processo1.start()
processo2.start()

In the processo1 I run some websockets that collect data from some websites. In the processo2 I manipulate this data to do some analysis.

The problem is that when I run the program it first runs the processo1 and only starts the processo2 when I stop at processo1 (Click the stop button on Pycharm).

By the way, does anyone indicate any specific course or material on multithreading and websockets? Thanks!

  • I did a simple test here and, if using 2 simpler functions as thread target, parallelized without problem. You mention that process 2 deals with data that comes from process 1. How do they communicate with each other? I imagine the problem is that one is waiting for the other, but this is happening in a code that is not included in the question.

1 answer

-1


good you are running to function inside the thread and not passing with parameter

example:



processo1 = Thread(target=stream.main()) # chamando a function
processo1.start()

processo1 = Thread(target=stream.main) # passando como parâmetro
processo1.start()


Browser other questions tagged

You are not signed in. Login or sign up in order to post.