Answer the question
In order to leave comments, you need to log in
Python: Why don't two function calls work in parallel?
I'm trying to call the function twice, but with different parameters, in parallel using the multiprocessing
. But in the terminal I see that only the p1 call is being executed (code below).
Tell me what is wrong and how to do it better? Thank you!
from django.apps import AppConfig
class CurrencyRatesConfig(AppConfig):
name = 'currency_rates'
def ready(self):
import time
from multiprocessing import Process
import currency_rates.ws_get_rates
p1 = Process(currency_rates.ws_get_rates.get_rates('1m', 'tBTCUSD', 'BTC2USD'))
p1.start()
p2 = Process(currency_rates.ws_get_rates.get_rates('1m', 'tIOTUSD', 'IOT2USD'))
p2.start()
p1.join()
p2.join()
Answer the question
In order to leave comments, you need to log in
and what does currency_rates.ws_get_rates.get_rates do?
given the "ws" prefix, we can assume that the function is related to web sockets
, perhaps it is doing some kind of blocking operation (waiting for a signal from the web socket)
from multiprocessing import Process
def test(arg):
raw_input(arg)
def test1(arg):
print(arg)
p1 = Process(test(1))
p1.start()
p2 = Process(test(2))
p2.start()
p1.join()
p2.join()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question