Dividing a process into subprocesses?

228 views
Skip to first unread message

Chelsea Kolb

unread,
Aug 19, 2016, 1:12:03 PM8/19/16
to python-simpy
Is there a good way to divide a process into subprocesses? 

For example, when a piece of equipment breaks down and requires 3 different parts for repair, I'd like to diagnose the equipment failure as a process, track each part individually as it is ordered, shipped, and arrives at the shop, and then again track the equipment repair as a process once all of the parts have arrived. I want a queueing system for each part in the subprocess and then a maintenance queue for the final repair. I'm having trouble understanding how these subprocesses can be queued independently and then brought back together for the final maintenance. Do you have any suggestions? 

Thanks! 

Stefan Scherfke

unread,
Aug 19, 2016, 4:59:11 PM8/19/16
to Chelsea Kolb, python-simpy
Hi Chelsea,

> Am 2016-08-19 um 19:12 schrieb Chelsea Kolb <chelsea...@gmail.com>:
>
> Is there a good way to divide a process into subprocesses?

yes, there are two different ways to have sub generators/processes:

import simpy


def sub(env):
yield env.timeout(1)


def master(env):
# Variant a: Just yield from sub(). It is uses like
# a normal generator and no real sub process is started:
yield from sub(env)

# Start an actual sub process. This way, you start it and
# wait until it terminates:
yield env.process(sub(env))

# You can also do stuff like this if you start an actual
# sub process:
child = env.process(sub(env))
yield env.timeout(0.5)
yield child


env = simpy.Environment()
env.process(master(env))
env.run()

Cheers,
Stefan


>
> For example, when a piece of equipment breaks down and requires 3 different parts for repair, I'd like to diagnose the equipment failure as a process, track each part individually as it is ordered, shipped, and arrives at the shop, and then again track the equipment repair as a process once all of the parts have arrived. I want a queueing system for each part in the subprocess and then a maintenance queue for the final repair. I'm having trouble understanding how these subprocesses can be queued independently and then brought back together for the final maintenance. Do you have any suggestions?
>
> Thanks!
>
> --
> 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 post to this group, send email to python...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/python-simpy/46087158-e248-4354-946f-22f6884149a6%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Chelsea Kolb

unread,
Aug 23, 2016, 4:13:43 PM8/23/16
to python-simpy
Thank you! 

Joe Pedersen

unread,
Jan 14, 2025, 8:50:56 AMJan 14
to python-simpy
Re: [SimPy] Dividing a process into subprocesses?

I've seen "yield from" produced by copilot, but I've never used it in my own simulations.  Everything I've found through internet searches is about using it in general, with I believe the main use case being coroutines.  I haven't found any explanation or example of its use in SimPy.  Searching this Google Group, I only found two emails using it, one being "Re: [SimPy] Dividing a process into subprocesses?"

Can anyone briefly explain what the "from" part does, or point me to any explanation online that you are aware of.

Thank you!

Best regards,
Joe

Ruud van der Ham

unread,
Jan 18, 2025, 8:35:36 AMJan 18
to Joe Pedersen, python-simpy
yield from is used when you want to create a function of method that contains a yield statement. To use that function/method as a generator, you need to call it with yield from.
E.g.
def double_time_out(t):
    yield env.time_put(2 * t)

yield from double_time(10)

It's always a bit confusing to not-so-experienced Python users ...

Please note that 'the other' Python discrete event simulation package, offers a completely yieldless version, which is much easier to understand. See www.salabim.org for details.

Ruud van der Ham
core developer salabim 


Reply all
Reply to author
Forward
0 new messages