pycharm freezes after running code for a long time

I've developed an algorithm trading program, and I need to run it 24/7.

Also, I just ran my code straight on pycharm, as I couldn't see any real downside to it (let me know if I'm wrong).

 

After running it for the last 24 hours, for which pycharm worked fine, i stopped the program to edit some code.

Editing and saving codes also worked fine.

But when I tried to rerun it after, it gave me an "Unknown Error" and froze for good. I had to close it via task manager since pressing X or Alt+F4 didn't work.

 

The exact same phenomenon has happened twice now, and I think it's not a coincidence. Do you know what could be potentially causing this?

 

My system is i7-8700k with 32gb of RAM.

When running my code, pycharm uses about 1.5gb of RAM and less than 30% of CPU.

I'm using the latest version of pycharm.

0
4 comments

Hi, 

Did the error come from PyCharm or the interpreter? Could you show a screenshot of the error? 

Anyway, running production code from IDE is not a good practice. Usually when you need to run something 24/7, you should setup a startup script and think of a way to relaunch it automatically in case it fails, usually using system manager such as systemd or runit.

1

Andrey Resler

Sorry, I didn't save a screenshot, but it wouldn't have helped anyway because there were no error logs or messages at all displayed on the console. Pycharm just froze after I clicked "Run".

I think it could have been a memory issue? When the freezing happened, Pycharm was taking up about 3GB of memory. But when running the program after rebooting Pycharm, it only takes up about 1.3GB. I've been running it for about 15 hours straight now and it's up to 2.3GB, so I'll see if it freezes again when it reaches that ~3GB mark.

 

As for running my code on directly on IDE, I have to put in a bunch of user inputs on program startup, so I can't make it restart automatically after failing, as it needs manual inputs.

I thought about turning it into a .exe file, but afaik it's not that different from running the code directly on IDE. Although the bigger reason is that I couldn't get pyinstaller to work properly, so I just gave up. This is my first python/programming project ever and I am really scared about screwing something up when it's working as intended - for the trading aspect of it, at least.

 

 

0

As for memory, you can try increasing Java heap: https://www.jetbrains.com/help/pycharm/increasing-memory-heap.html

As for running 24/7:

Since you mentioned .exe file, you seem to be on Windows. First, if you don't know how to run python scripts from the command line, please see:

https://docs.python.org/3/using/cmdline.html#command-line

If you're using virtualenv interpreter in PyCharm, you may need to activate it in the command line as well:
https://virtualenv.pypa.io/en/latest/user_guide.html#activators

Then, you can create a startup .bat script to run your code with a single desktop shortcut. No need to create .exe files.

I really wound't recommend running a script 24/7 in the IDE.

1

Andrey Resler I understand the better workaround of running on background or console. Still this is needed for example to debug 24/7 as it is a personal project and from time to time I like to peek into the variables without printing everything into the logs. So it would still be a problem with the IDE. My guess is that if you have used it for long enough you have encountered the issue. Please fix. (I don't have the tools or the time to collect data which is jetbrain's job with such a pitty bug, an app freezing on 2022)

0

Please sign in to leave a comment.