Race condition when creating multiple put requests

23 views
Skip to first unread message

Cornelius Sheahan

unread,
Apr 29, 2025, 5:49:36 AMApr 29
to python-simpy

I am using SimPy to model a manufacturing workflow, and am running into a race condition type problem.

A buffer/queue modelled as a store can provide product to many different machines also modelled as stores. My current approach to this is to make a put request to each machine and assuming they become available at different times I can cancel the extra requests. This of coarse doesn't account for when two or more machines become available at the same unit time.

I can make some quick gains on reducing the problem by checking if successors are immediately available and only making one request but that doesn't solve for the case where they become available simultaneously.

I have posted in more detail on StackOverflow

Advice on architectural or implementation level would be appreciated

Andrei Savu

unread,
Apr 29, 2025, 10:34:52 AMApr 29
to python-simpy
Hi Neil,

To avoid the race condition a straightforward approach is to switch from a push based approach to a pull based approach and create a setup where machines announce themselves as idle to a router.

I put together an example implement you can run in the browser: https://teachyourselfsystems.com/sandbox#machines 

Cheers,
Andrei

Cornelius Sheahan

unread,
Apr 30, 2025, 3:48:20 AMApr 30
to Andrei Savu, python-simpy
Hi Andrei

Thanks for your reply, this has been helpful. 

Could a "Has Capacity" type event be created to be equivalent to your token get request, if not how would they differ? 

Thanks,
Neil

--
You received this message because you are subscribed to the Google Groups "python-simpy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-simpy...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/python-simpy/415e396b-075f-4563-a57d-4af51f4da841n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages