import time
import threading as td
import multiprocessing as mp
import pandas as pd
import numpy as np
df = pd.DataFrame()
def s_run():
data = {"one": np.random.randn(4), "two": np.linspace(1, 4, 4), "three": ['zhangsan', '李四', 999, 0.1]}
df1 = pd.DataFrame(data, index=[1, 2, 3, 4])
global df
df = pd.concat([df, df1], ignore_index=True)
def s_start():
s1 = mp.Process(target=s_run)
s2 = mp.Process(target=s_run)
s3 = mp.Process(target=s_run)
mp_list = [s1, s2, s3]
for t in mp_list:
t.start()
for t in mp_list:
t.join()
while True:
if not s1.is_alive():
s1 = mp.Process(target=s_run)
s1.start()
if not s2.is_alive():
s2 = mp.Process(target=s_run)
s2.start()
if not s3.is_alive():
s3 = mp.Process(target=s_run)
s3.start()
for t in mp_list:
t.join()
time.sleep(1)
def p_run():
print(len(df))
def p_start():
p1 = mp.Process(target=p_run)
p2 = mp.Process(target=p_run)
p3 = mp.Process(target=p_run)
mp_list = [p1, p2, p3]
for t in mp_list:
t.start()
for t in mp_list:
t.join()
while True:
if not p1.is_alive():
p1 = mp.Process(target=p_run)
p1.start()
if not p2.is_alive():
p2 = mp.Process(target=p_run)
p2.start()
if not p3.is_alive():
p3 = mp.Process(target=p_run)
p3.start()
for t in mp_list:
t.join()
time.sleep(1)
def main():
s = td.Thread(target=s_start)
p = td.Thread(target=p_start)
s.start()
p.start()
s.join()
p.join()
if __name__ == '__main__':
main()