The invention relates to a rotary machine for conveying a fluid, comprising a drive unit (2) for driving a shaft (5), a running wheel (31) arranged on the shaft (5) for conveying the fluid, at least one mechanical gasket (6) for sealing the shaft (5) a first and a second heat exchange system (41, 42) for cooling or for heating the mechanical gasket (6), wherein the first heat exchange system (41) has a fluid heat carrier for directly impacting the mechanical gasket (6). The second heat exchange system (42) comprises a heat exchange jacket (421), through which a fluid heat carrier can flow without direct contact with the mechanical gasket (6). The first and the second heat exchange system (41 42) form a common heat exchange system (40), in which a common fluid heat carrier can be circulated, and an impeller (44) for circulating the fluid heat carrier in the heat exchange system (40) is provided. The invention further relates to a method for the heat exchange in a rotary machine.