A good practice is to set some time and money limits. For example, you can decide before you start how much time you will play and how much money you are willing to risk. If such self-limitations are not enough, you might need to find ways of holding yourself to your plan. For example, most poker sites offer the possibility to self-exclude from gambling for a given time.
Also, you should play only with money you know you can afford to lose financially and psychologically. Decide upfront what this amount is for you on a daily, weekly, and monthly basis, and commit to not breaching this limit.