R
R
R.2017-10-18 14:39:41
Django
R., 2017-10-18 14:39:41

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

1 answer(s)
S
Stanislav Pugachev, 2017-10-18
@Stqs

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

if you use the test1 function, then we see 2 prints;
if the test function, then we see only the input from the first call.
then the process is blocked

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question