On Wed, Nov 23, 2022 at 1:43 PM Shaheed Haque <shaheedha...@gmail.com> wrote:
>
> Are all the threads in the same Python process?

No

> Or the same machine?

No

> Do they have to persist across process (or machine) restarts?

Yes.

Playing around with using F() but still don't have it working as desired.

> On Wed, 23 Nov 2022, 16:57 Larry Martell, <larry.mart...@gmail.com> wrote:
>>
>> I have an app that needs to get a unique ID. Many threads run at the
>> same time that need one. I would like the IDs to be sequential. When I
>> need a unique ID I do this:
>>
>> with transaction.atomic():
>>     max_batch_id =
>> JobStatus.objects.select_for_update(nowait=False).aggregate(Max('batch_id'))
>>     json_dict['batch_id'] = max_batch_id['batch_id__max'] + 1
>>     status_row = JobStatus(**json_dict)
>>     status_row.save()
>>
>> But multiple jobs are getting the same ID. Why does the code not work
>> as I expect? What is a better way to accomplish what I need?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACwCsY7A_zk%3DxJ3vg8csCSFPamkjtzm6fRGbzNjru1e2aJfa3A%40mail.gmail.com.

Reply via email to