У меня возникли проблемы с обменом объектом (dataframe) между двумя процессами через Queue.
Первый процесс получает данные из очереди, второй помещает данные в очередь. Процесс put быстрее, поэтому процесс get должен очистить очередь, прочитав весь объект.
У меня странное поведение, потому что мой код работает отлично и, как и ожидалось, но только для 100 строк в кадре данных, для 1000 строк процесс получения всегда принимает только 1 объект.
import multiprocessing, time, sys
import pandas as pd
NR_ROWS = 1000
i = 0
def getDf():
global i, NR_ROWS
myheader = ["name", "test2", "test3"]
myrow1 = [ i, i+400, i+250]
df = pd.DataFrame([myrow1]*NR_ROWS, columns = myheader)
i = i+1
return df
def f_put(q):
print "f_put start"
while(1):
data = getDf()
q.put(data)
print "P:", data["name"].iloc[0]
sys.stdout.flush()
time.sleep(1.55)
def f_get(q):
print "f_get start"
while(1):
data = pd.DataFrame()
while not q.empty():
data = q.get()
print "get"
if not data.empty:
print "G:", data["name"].iloc[0]
else:
print "nothing new"
time.sleep(5.9)
if __name__ == "__main__":
q = multiprocessing.Queue()
p = multiprocessing.Process(target=f_put, args=(q,))
p.start()
while(1):
f_get(q)
p.join()
Вывод для 100-строчного фрейма данных, get-process принимает все объекты
f_get start
nothing new
f_put start
P: 0 # put 1.object into the queue
P: 1 # put 2.object into the queue
P: 2 # put 3.object into the queue
P: 3 # put 4.object into the queue
get # get-process takes all 4 objects from the queue
get
get
get
G: 3
P: 4
P: 5
P: 6
get
get
get
G: 6
P: 7
P: 8
Вывод для кадра данных 1000 строк, get-process принимает только один объект.
f_get start
nothing new
f_put start
P: 0 # put 1.object into the queue
P: 1 # put 2.object into the queue
P: 2 # put 3.object into the queue
P: 3 # put 4.object into the queue
get <-- #!!! get-process takes ONLY 1 object from the queue!!!
G: 1
P: 4
P: 5
P: 6
get
G: 2
P: 7
P: 8
P: 9
P: 10
get
G: 3
P: 11
Есть идеи, что я делаю неправильно и как передать больший фрейм данных?
__version__
: панды 0.16.2, многопроцессорность 0.70a1, питон 2.7.10) - person chris-sc   schedule 11.08.2015DataFrame
как таковом, но и во всех объектах Python, размеры которых превышают некоторый порог, который будет зависеть от системы. - person chris-sc   schedule 12.08.2015