I actually was aware that such reuse could take place, so I did check if they point to the same object. But in my case, those reprs don't give the same output as in your case.
Here's my updated code and output:
def channel_test_2():
print('Play the sound on channel1')
channel1 = dog.play()
print('channel1=', channel1)
sleep(1)
print('After 1 second: channel1 - ', channel1.get_sound() == dog)
sleep(6)
print('After 7 seconds: channel1 - ', channel1.get_sound() == dog)
print('Play the sound on channel2')
channel2 = dog.play()
print('channel2=', channel2)
sleep(1)
print('After 1 seconds: channel1 - ', channel1.get_sound() == dog, ', channel2 - ', channel2.get_sound() == dog)
sleep(3)
print('After 4 seconds: channel1 - ', channel1.get_sound() == dog, ', channel2 - ', channel2.get_sound() == dog)
sleep(3)
print('After 7 seconds: channel1 - ', channel1.get_sound() == dog, ', channel2 - ', channel2.get_sound() == dog)
print('channel1=', channel1)
print('channel2=', channel2)
print('Are they the same?', channel1 == channel2)
Play the sound on channel1
channel1= <Channel object at 0xb642bfb0>
After 1 second: channel1 - True
After 7 seconds: channel1 - False
Play the sound on channel2
channel2= <Channel object at 0xb5563450>
After 1 seconds: channel1 - True , channel2 - True
After 4 seconds: channel1 - True , channel2 - True
After 7 seconds: channel1 - False , channel2 - False
channel1= <Channel object at 0xb642bfb0>
channel2= <Channel object at 0xb5563450>
Are they the same? False
As you can see, in my case the channels point to different addresses, but still behave as if they are linked. Maybe it is important on what platform I am running this code?
My platform:
- Raspberry Pi Zero W
- Raspbian GNU/Linux 10 (buster)
- Python 3.7.3
- pygame 2.0.0 (SDL 2.0.9)
I am aware of the channel end_event but since the number of custom event IDs is very limited, I had to implement my own solution (a wrapper class for the Channel object) for executing a function when the sound has finished playing, using a timer object, set to sound.get_length(). I have now implemented extra property in my wrapper class that tracks if the sound is currently playing. This works fine, but it still remains a mystery, why those channels behave as they do, even though they point to different addresses (in my case).