python - Multi-threading different scripts -


i have aa few scripts written in python. trying multi thread them.

when script starts. scripts b, c, , d start. after runs, a2 run. after b runs, b2 run, b3. c , d have no follow scripts.

i have checked scripts independent of each other.
planning on using "exec" launch them, , use "launcher" on linux , windows."

i have other multi thread scripts procedure 5 threads. throwing me because procedures different start , run @ same time.

ok i'm still not sure problem is, that's way i'd solve problem:

#main.py multiprocessing import process import scripta # import other scripts  def handle_script_a(*args):     print("call 1 or several functions script or calculate stuff beforehand")     scripta.foo(*args)  if __name__ == '__main__':     p = process(target=handle_script_a, args=("either so", ))     p1 = process(target=scripta.foo, args=("or so", ))     p.start()     p1.start()     p.join()     p1.join()  # scripta.py: def foo(*args):     print("function foo called args:")     arg in args:         print(arg) 

you can either call function directly or if want call several functions in 1 process use small wrapper it. no platform dependent code, no ugly execs , can create/join processes in whatever way fancies you.

and small example of queue interprocess communication - pretty stolen python api ;)

from multiprocessing import process, queue  def f(q):     q.put([42, none, 'hello'])  if __name__ == '__main__':     q = queue()     p = process(target=f, args=(q,))     p.start()     print(q.get())    # prints "[42, none, 'hello']"     p.join() 

create queue , give 1 or more processes. note get() blocks, if want non blocking can use get_nowait() or specify timeout 2nd argument. if want shared objects there'd multiprocessing.array or multiprocessing.value, read documentation specific information doc link if you've got more questions relative ipc create new question - extremely large topic in itself.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -