0

I want to use the module multiprocessing to execute 2 functions at the same time but it doesn't work. the code in these two functions depends on the library of these two instruments, there has no matter with multiprocessing

import multiprocessing as mp

def mesure_rfb():
  libc.StartMeas()
  time.sleep(0.5)
  while libc.Measuring() == -1:
      time.sleep(1)

def mesure_nrt():
  global ave,rev,chrono
  my_nrt.zeroing()
  my_nrt.setimeout(100000)
  tstart = time.time()
  b=2
  ave,rev,chrono = my_nrt.measurement(times=b)
  a=time.time()-tstart
  print('measurement cost: ' , a,' s')
  print('a measurement costs: ' , a/b,' s')

if __name__ == '__main__':
  rfb = mp.Process(name='rfb measuring', target=mesure_rfb)
  nrt = mp.Process(name='nrt measuring', target=mesure_nrt)
  rfb.start()
  nrt.start()
  rfb.join()
  nrt.join()

As soon as I run this part of my programme, it executes only the function mesure_nrt. I am quite new to python. Any help will be appreciated.

Elephie
  • 41
  • 1
  • 4
  • No it runs the two concurrently, but the first process does not print nor returns anything. – Willem Van Onsem Jul 25 '17 at 12:39
  • What indicates to you that rfb is not running? – Xingzhou Liu Jul 25 '17 at 12:42
  • Thank you for your answer but in fact, the first function returns some data that I can see in a logiciel connected to an instruments, but in this program, it doesn't show that, Is there any problem with multiprocessing in my program? – Elephie Jul 25 '17 at 12:44
  • it's running, just correct the indentation – Kallz Jul 25 '17 at 12:45
  • Sorry that I didn't put the entire code for the first function, but it indeed return something – Elephie Jul 25 '17 at 12:45
  • Could you tell me what's the best way yo execute two functions at the same time, with lock or something like this? Thanks very much, – Elephie Jul 25 '17 at 12:49
  • I tried several times and I find out the problem is that the program above can't execute any function, and I tried other examples, doesn't work neither, I am using IDLE, is the problem of console? – Elephie Jul 25 '17 at 13:05
  • Relevant: [Can multiprocessing Process class be run from IDLE](https://stackoverflow.com/questions/35293178/can-multiprocessing-process-class-be-run-from-idle) – stovfl Jul 25 '17 at 18:23

0 Answers0