2

Now I learn the simpy library of python. Could you explain me why bitwise-or is used in this example. Why we can't use simple or statement.

results = yield req | env.timeout(patience)
Kenenbek Arzymatov
  • 8,439
  • 19
  • 58
  • 109
  • 1
    It would help to have a little more context, what is stored in req for example? And what does env return? Knowing what they are might help explain the benefit of bitwise or'ing them. Also, is there any chance it's an error in the example? – srowland Mar 17 '16 at 16:42

1 Answers1

3

From SimPy's documentation of Core Event Types

This class also implements and() (&) and or() (|). If you concatenate two events using one of these operators, a Condition event is generated that lets you wait for both or one of them.

This implies that req and env.timeout(patience) are both events and we'll yield the first one that occurs. I.e.

results = yield (req | env.timeout(patience))

To answer your original question, it appears you can use or instead but that might not make what's really going on any clearer and lead to editing errors if one assumes it's a regular old or.

cdlane
  • 40,441
  • 5
  • 32
  • 81