Using create_batch method of factory.django.DjangoModelFactory with multiprocessing

547 views
Skip to first unread message

Jaysinh Shukla

unread,
Aug 25, 2016, 8:01:50 AM8/25/16
to facto...@googlegroups.com
Hello members,

Have anyone tried using
[create_batch](http://factoryboy.readthedocs.io/en/latest/reference.html#factory.create_batch)
method of [factory.django.DjangoModelFactory](
factory.django.DjangoModelFactory) Class with multiprocessing? I tried
and getting wired result.

I created 4 worker process which calls create_batch with various number
of arguments but I found it creates duplicated number of records.

For example, I am calling 4 worker process with argument of
create_batch(12) then as a result it create 3 similar records for all 12
records. 1,2,3 are same in data. 4,5,6 are same in data. 7,8,9 are same
in data, 10,11,12 are same in data.

Can anyone guide me, How can I solve this?

Raphaël Barrois

unread,
Aug 25, 2016, 8:59:03 AM8/25/16
to Jaysinh Shukla, facto...@googlegroups.com
Hi,

Behind the scenes, factory_boy uses a per-process monotonic counter (for all sequences, iterators, etc.)

If you want different items in each subprocess, you'll have to assign different initial sequence counters to each
factory in each process, with http://factoryboy.readthedocs.io/en/latest/reference.html#factory.Factory.reset_sequence

However, why do you need to create those instances in subprocesses?


--
Raphaël

Reply all
Reply to author
Forward
0 new messages