pycharm-odoo
pycharm-odoo copied to clipboard
High CPU usage on PyCharm
While I was trying to create a script to do auto-upgrades, my laptop CPU usage went of the chart all of a sudden, and now is very hard to add just 1 line of code.
I have a 32GB of RAM and a 12th Gen Intel Core i7-1270P with 12 cores, so I don't think this is a hardware issue.
Here is the code
# -*- coding: utf-8 -*-
# set server timezone in UTC before time module imported
__import__('os').environ['TZ'] = 'UTC'
import logging
import sys
import odoo
from odoo.tools import config
# Get the logger
_logger = logging.getLogger(__name__)
def _upd_db(cr, db_nm):
# Get the superuser ID
uid = odoo.SUPERUSER_ID
# Get the environment context
ctx = odoo.api.Environment(cr, uid, {})['res.users'].context_get()
# Get the environment
env = odoo.api.Environment(cr, uid, ctx)
# Get the module model
Mdl = env['ir.module.module']
# Update module list
Mdl.update_list()
# Find module `xgo_mdl_auto_upd`
xgo_mdl_auto_upd = Mdl.search([('name', '=', 'xgo_mdl_auto_upd')])
# If module `xgo_mdl_auto_upd` does not exist:
if not xgo_mdl_auto_upd:
# Log a message and continue
_logger.error('Module `xgo_mdl_auto_upd` does not exist')
return
# If module `xgo_mdl_auto_upd` is uninstalled
if xgo_mdl_auto_upd.state == 'uninstalled':
# Install module `xgo_mdl_auto_upd`
xgo_mdl_auto_upd.button_immediate_install()
# Since the module `xgo_mdl_auto_upd` was installed.
# We need to remove the saved checksums to force the update of all modules.
from odoo.addons.module_auto_update.models.module import PARAM_INSTALLED_CHECKSUMS
env["ir.config_parameter"].set_param(PARAM_INSTALLED_CHECKSUMS, "{}")
# Commit the changes
env.cr.commit()
# Return False to indicate that the database was not processed
return False
# If module `xgo_mdl_auto_upd` installation was unfinished
elif xgo_mdl_auto_upd.state == 'to install':
# Cancel the installation
xgo_mdl_auto_upd.button_install_cancel()
# Commit the changes
env.cr.commit()
# Return False to indicate that the database was not processed
return False
# If module `xgo_mdl_auto_upd` is not installed
elif xgo_mdl_auto_upd.state != 'installed':
# Get module `xgo_mdl_auto_upd` state
xgo_mdl_auto_upd_state = xgo_mdl_auto_upd.state
# Get the module states as a dictiona
mdl_sts_dct = dict(Mdl._fields['state']._description_selection(Mdl.env))
# Log a message and continue
_logger.error(
'Module `xgo_mdl_auto_upd` state is "%s" instead of "%s"',
mdl_sts_dct[xgo_mdl_auto_upd_state], mdl_sts_dct['installed']
)
return
# Update all modules with changes checksums
getattr(Mdl, 'upgrade_changed_checksum')()
# Commit the changes
env.cr.commit()
# Log a message
_logger.info('Database "%s" processed successfully', db_nm)
def main():
# Get the logger
global _logger
# Get the arguments
args = sys.argv[1:]
# Set the program name in the configuration parser
config.parser.prog = 'xgo_cli_auto_upd'
# Parse the configuration
config.parse_config(args)
# Report the configuration of the server
odoo.cli.server.report_configuration()
# Get the database list
db_lst = odoo.service.db.list_dbs(True)
# Get a list of incompatible databases
bad_db_lst = odoo.service.db.list_db_incompatible(db_lst)
# Filter-out the incompatible databases
db_lst = list(set(db_lst) - set(bad_db_lst))
# Sort the database list
db_lst.sort()
# For each database in the list
for db_nm in db_lst:
# Add 50 lines to the log
_logger.info('\n' * 50)
# Log a message
_logger.info('Processing database "%s"', db_nm)
# Unfinished variable
unfinished = True
while unfinished:
# Get model registry
registry = odoo.registry(db_nm)
# Get the cursor
with registry.cursor() as cr:
try:
# Perform the database update
# If the database was not processed (False is returned)
unfinished = _upd_db(cr, db_nm) is False
except Exception as e:
# Log the exception
_logger.exception('Failed to update database:\n%s', e)
# Rollback the transaction
cr.rollback()
# Break the loop
break
if __name__ == "__main__":
main()
Could you please add this code into a file and try editing it?
Hi @jcfernandez-890825 ,
I just tested your code on Macbook Pro M1 16GB. Everything is working fine without any performance issues.
Hi @trinhanhngoc
Mmmm... this is weird ...
As soon as I disable the plugin the CPU usage goes away, maybe there is a problem when the Odoo plugin interacts with another plugin ior feature?
Is there a inspection/analysis setting thing that might be causing this?
@jcfernandez-890825 ,
I need more information: PyCharm version? Odoo version? Other plugins?
@trinhanhngoc
Here is my info:
PyCharm 2024.1.4 (Professional Edition)
Build #PY-241.18034.82, built on June 24, 2024
Licensed to Juan Carlos Fernández
Subscription is active until November 13, 2024.
Runtime version: 17.0.11+1-b1207.24 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Linux 5.15.0-107-generic
GC: G1 Young Generation, G1 Old Generation
Memory: 10240M
Cores: 16
Non-Bundled Plugins:
com.jetbrains.space (241.18034.4)
Statistic (4.2.14)
dev.meanmail.plugin.nginx-intellij-plugin (2024.3)
XPathView (241.15989.65)
net.seesharpsoft.intellij.plugins.csv (3.3.0-241)
com.github.copilot (1.5.11.5872)
dev.ngocta.pycharm-odoo (2024.5.1.241)
com.intellij.bigdatatools.core (241.18034.62)
com.intellij.bigdatatools.binary.files (241.14494.158)
com.intellij.bigdatatools.rfs (241.18034.62)
zielu.gittoolbox (500.2.10+233)
Current Desktop: X-Cinnamon
@trinhanhngoc
Since this is not a module, but just a python package with DevOps scripts.
Maybe is indexing constantly all modules because there is no manifest?
@trinhanhngoc
I just tested your code on Macbook Pro M1 16GB. Everything is working fine without any performance issues.
When you did this did you added the code inside a module folder?
When I add a manifest file to xgo_dev_ops. The problem stops.
@jcfernandez-890825 ,
No, I created a temp file in the root of the Odoo source code.
I have the same problem on my pyCharm :
%CPU Subsystem ... 162.1 Plugin Odoo: dev.ngocta.pycharm.odoo.module ...
PyCharm 2024.1.6 (Professional Edition) Build #PY-241.19072.16, built on August 8, 2024
Runtime version: 17.0.11+1-b1207.30 aarch64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. macOS 14.5 GC: G1 Young Generation, G1 Old Generation Memory: 4096M Cores: 10 Metal Rendering is ON
dev.ngocta.pycharm-odoo (2024.6.1.241)
@imlopes ,
How long does the plugin make high CPU usage when you check?
@imlopes ,
How long does the plugin make high CPU usage when you check?
Now it's deactivated on my machine but the problem is :
- When I'm writing a code line (so I think the plugin try to load some things)
- When I'm using the Run Configuration (I had to change to the normal Python Run Configuration because the plugin was freezing my pyCharm)
For information :
- I'm using docker compose
- I work on projects with many OCA submodules
Here my run configuration when I was using the plugin :
<component name="ProjectRunConfigurationManager"> <configuration default="false" name="Odoo" type="Odoo" factoryName="Odoo" nameIsGenerated="true"> <module name="PROJECT" /> <option name="ENV_FILES" value="" /> <option name="INTERPRETER_OPTIONS" value="" /> <option name="PARENT_ENVS" value="true" /> <envs> <env name="PYTHONUNBUFFERED" value="1" /> </envs> <option name="SDK_HOME" value="" /> <option name="WORKING_DIRECTORY" value="/odoo" /> <option name="IS_MODULE_SDK" value="true" /> <option name="ADD_CONTENT_ROOTS" value="true" /> <option name="ADD_SOURCE_ROOTS" value="true" /> <EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" /> <PathMappingSettings> <option name="pathMappings"> <list> <mapping local-root="$PROJECT_DIR$/PROJECT_odoo/odoo" remote-root="/odoo" /> </list> </option> </PathMappingSettings> <option name="SCRIPT_NAME" value="/odoo/src/odoo-bin" /> <option name="PARAMETERS" value="--dev xml" /> <option name="SHOW_COMMAND_LINE" value="false" /> <option name="EMULATE_TERMINAL" value="true" /> <method v="2" /> </configuration> </component>%
And reading this comment I think I don't give you the answer for your question, so :
- How long does the plugin make high CPU usage when you check?
- It depends. Some times was fast, I mean, less than 1 sec (the time to display the high usage and then drop down to less than 40%) but when using Run Conf, it was long long time
@imlopes ,
Thanks for the additional information. Can you capture screenshots of the Activity Monitor window when the plugin makes high CPU usage for a long time (with Odoo Run Configuration)?
@trinhanhngoc
https://drive.google.com/file/d/10Ciotfj-OFzFMTvK7-Yo1zKVVS85xME7/view?usp=sharing
I can't use the plugin :/ Maybe I have a problem with the indexes on my project as I use a lot of submodules. In this video, I was not using the Run Conf, I was just typing my code and IMHO the autocomp is the problem :/
@imlopes ,
The high load is strange. Is the source code you are using public on github?. I want to reproduce the problem on my laptop.
Yes, I agreed w you, is really strange. My project is private but maybe you can "reproduce" creating an odoo project and then, adding many submodules:
[submodule "odoo/src"]
path = odoo/src
url = [email protected]:OCA/odoo.git
branch = 16.0
[submodule "odoo/external-src/crm"]
path = odoo/external-src/crm
url = [email protected]:OCA/crm.git
branch = 16.0
[submodule "odoo/external-src/hr"]
path = odoo/external-src/hr
url = [email protected]:OCA/hr.git
branch = 16.0
[submodule "odoo/external-src/partner-contact"]
path = odoo/external-src/partner-contact
url = [email protected]:OCA/partner-contact.git
branch = 16.0
[submodule "odoo/external-src/report-print-send"]
path = odoo/external-src/report-print-send
url = [email protected]:OCA/report-print-send.git
branch = 16.0
[submodule "odoo/external-src/reporting-engine"]
path = odoo/external-src/reporting-engine
url = [email protected]:OCA/reporting-engine.git
branch = 16.0
[submodule "odoo/external-src/server-auth"]
path = odoo/external-src/server-auth
url = [email protected]:OCA/server-auth.git
branch = 16.0
[submodule "odoo/external-src/server-backend"]
path = odoo/external-src/server-backend
url = [email protected]:OCA/server-backend.git
branch = 16.0
[submodule "odoo/external-src/server-brand"]
path = odoo/external-src/server-brand
url = [email protected]:OCA/server-brand.git
branch = 16.0
[submodule "odoo/external-src/server-env"]
path = odoo/external-src/server-env
url = [email protected]:OCA/server-env.git
branch = 16.0
[submodule "odoo/external-src/server-tools"]
path = odoo/external-src/server-tools
url = [email protected]:OCA/server-tools.git
branch = 16.0
[submodule "odoo/external-src/server-ux"]
path = odoo/external-src/server-ux
url = [email protected]:OCA/server-ux.git
branch = 16.0
And so on... And use this structure : https://github.com/camptocamp/docker-odoo-project/tree/master/example
I confirm having the same problem. I'm using Docker for running Odoo and after some time (not after fresh PyCharm start) the CPU usage gets to 500-600% and PyCharm becomes practically non-responsive. Disabling Odoo plugin resolved this so far but I'd be grateful if some fix can be provided. My current config is:
PyCharm 2025.2 Build #PY-252.23892.439, built on August 4, 2025 Source revision: e7a5644c801f1 Runtime version: 21.0.7+6-b1038.58 aarch64 (JCEF 122.1.9) VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Toolkit: sun.lwawt.macosx.LWCToolkit macOS 15.5 GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation Memory: 2048M Cores: 8 Metal Rendering is ON Registry: ide.experimental.ui=true python.debug.use.single.port=true Non-Bundled Plugins: org.jetbrains.junie (252.204.141) net.antelle.intellij-xcode-dark-theme (1.2.4) com.intellij.ml.llm (252.23892.439) net.seesharpsoft.intellij.plugins.csv (4.0.2) Karma (252.25204.0) mobi.hsz.idea.gitignore (4.5.6) dev.ngocta.pycharm-odoo (2025.4.5.252)
In my project where the issue occurs I currently have 8 repositories, some with multiple submodules.
@KDRdev ,
You can try increasing IDE memory (e.g 4096 MB): https://www.jetbrains.com/help/pycharm/increasing-memory-heap.html
Yes, I agreed w you, is really strange. My project is private but maybe you can "reproduce" creating an odoo project and then, adding many submodules:
[submodule "odoo/src"] path = odoo/src url = [email protected]:OCA/odoo.git branch = 16.0 [submodule "odoo/external-src/crm"] path = odoo/external-src/crm url = [email protected]:OCA/crm.git branch = 16.0 [submodule "odoo/external-src/hr"] path = odoo/external-src/hr url = [email protected]:OCA/hr.git branch = 16.0 [submodule "odoo/external-src/partner-contact"] path = odoo/external-src/partner-contact url = [email protected]:OCA/partner-contact.git branch = 16.0 [submodule "odoo/external-src/report-print-send"] path = odoo/external-src/report-print-send url = [email protected]:OCA/report-print-send.git branch = 16.0 [submodule "odoo/external-src/reporting-engine"] path = odoo/external-src/reporting-engine url = [email protected]:OCA/reporting-engine.git branch = 16.0 [submodule "odoo/external-src/server-auth"] path = odoo/external-src/server-auth url = [email protected]:OCA/server-auth.git branch = 16.0 [submodule "odoo/external-src/server-backend"] path = odoo/external-src/server-backend url = [email protected]:OCA/server-backend.git branch = 16.0 [submodule "odoo/external-src/server-brand"] path = odoo/external-src/server-brand url = [email protected]:OCA/server-brand.git branch = 16.0 [submodule "odoo/external-src/server-env"] path = odoo/external-src/server-env url = [email protected]:OCA/server-env.git branch = 16.0 [submodule "odoo/external-src/server-tools"] path = odoo/external-src/server-tools url = [email protected]:OCA/server-tools.git branch = 16.0 [submodule "odoo/external-src/server-ux"] path = odoo/external-src/server-ux url = [email protected]:OCA/server-ux.git branch = 16.0And so on... And use this structure : https://github.com/camptocamp/docker-odoo-project/tree/master/example
Hello @imlopes ,
Do you still experience the performance issue with the latest version of PyCharm and the Odoo IDE plugin?
@trinhanhngoc honestly ? I stopped using the plugin due to the performance issues.
But If I'm not wrong, I retried with a new version (not sure if the last one) and the problem was still there :/
If I can help in anything, don't hesitate!
@imlopes ,
Sad. If you can reproduce the issue with the latest plugin version (2025.7.0), could you take a CPU usage profiling snapshot when the issue occurs and provide me with the snapshot file. I would help me a lot in finding the root cause. Thank you so much.
@imlopes ,
You can find instructions on how to take CPU usage profiling snapshot here: https://www.jetbrains.com/help/go/performance-issues-high-cpu-usage.html