Passa al contenuto
Odoo Menu
  • Accedi
  • Provalo gratis
  • App
    Finanze
    • Contabilità
    • Fatturazione
    • Note spese
    • Fogli di calcolo (BI)
    • Documenti
    • Firma
    Vendite
    • CRM
    • Vendite
    • Punto vendita Negozio
    • Punto vendita Ristorante
    • Abbonamenti
    • Noleggi
    Siti web
    • Configuratore sito web
    • E-commerce
    • Blog
    • Forum
    • Live chat
    • E-learning
    Supply chain
    • Magazzino
    • Produzione
    • PLM
    • Acquisti
    • Manutenzione
    • Qualità
    Risorse umane
    • Dipendenti
    • Assunzioni
    • Ferie
    • Valutazioni
    • Referral dipendenti
    • Parco veicoli
    Marketing
    • Social marketing
    • E-mail marketing
    • SMS marketing
    • Eventi
    • Marketing automation
    • Sondaggi
    Servizi
    • Progetti
    • Fogli ore
    • Assistenza sul campo
    • Helpdesk
    • Pianificazione
    • Appuntamenti
    Produttività
    • Comunicazioni
    • Approvazioni
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    App di terze parti Odoo Studio Piattaforma cloud Odoo
  • Settori
    Retail
    • Libreria
    • Negozio di abbigliamento
    • Negozio di arredamento
    • Alimentari
    • Ferramenta
    • Negozio di giocattoli
    Cibo e ospitalità
    • Bar e pub
    • Ristorante
    • Fast food
    • Pensione
    • Grossista di bevande
    • Hotel
    Agenzia immobiliare
    • Agenzia immobiliare
    • Studio di architettura
    • Edilizia
    • Gestione immobiliare
    • Impresa di giardinaggio
    • Associazione di proprietari immobiliari
    Consulenza
    • Società di contabilità
    • Partner Odoo
    • Agenzia di marketing
    • Studio legale
    • Selezione del personale
    • Audit e certificazione
    Produzione
    • Tessile
    • Metallo
    • Arredamenti
    • Alimentare
    • Birrificio
    • Ditta di regalistica aziendale
    Benessere e sport
    • Club sportivo
    • Negozio di ottica
    • Centro fitness
    • Centro benessere
    • Farmacia
    • Parrucchiere
    Commercio
    • Tuttofare
    • Hardware e assistenza IT
    • Ditta di installazione di pannelli solari
    • Calzolaio
    • Servizi di pulizia
    • Servizi di climatizzazione
    Altro
    • Organizzazione non profit
    • Ente per la tutela ambientale
    • Agenzia di cartellonistica pubblicitaria
    • Studio fotografico
    • Punto noleggio di biciclette
    • Rivenditore di software
    Carica tutti i settori
  • Community
    Apprendimento
    • Tutorial
    • Documentazione
    • Certificazioni 
    • Formazione
    • Blog
    • Podcast
    Potenzia la tua formazione
    • Programma educativo
    • Scale Up! Business Game
    • Visita Odoo
    Ottieni il software
    • Scarica
    • Versioni a confronto
    • Note di versione
    Collabora
    • Github
    • Forum
    • Eventi
    • Traduzioni
    • Diventa nostro partner
    • Servizi per partner
    • Registra la tua società di contabilità
    Ottieni servizi
    • Trova un partner
    • Trova un contabile
    • Incontra un esperto
    • Servizi di implementazione
    • Testimonianze dei clienti
    • Supporto
    • Aggiornamenti
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Richiedi una demo
  • Prezzi
  • Aiuto

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Contabilità
  • Magazzino
  • PoS
  • Progetti
  • MRP
All apps
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
Assistenza

Cron job showing error: RuntimeError: OrderedDict mutated during iteration

Iscriviti

Ricevi una notifica quando c'è un'attività per questo post

La domanda è stata contrassegnata
cronbugcronjobv14
1 Rispondi
8468 Visualizzazioni
Avatar
Dries Cox

Hello Community, 

I have a problem with the cron job that stops on a regular basis running after a while. I have been looking into the logs and I came across this error:

RuntimeError: OrderedDict mutated during iteration

Full log:

2022-03-28 12:26:57,168 344737 INFO test-server: xxx\.xxx\.xxx\.xxx\ \-\ \-\ \[28\ Mar2022\ 12:26:57\\]\\ "POST\\ /longpolling/poll\\ HTTP/1\\.0"\\ 200\\ \\-\\ 8\\ 0\\.002\\ 50\\.007
Exception\ in\ thread\ odoo\.service\.cron\.cron1:
Traceback\ \(most\ recent\ call\ last\):
\\ \\ File\\ "/usr/lib/python3\\.9/threading\\.py",\\ line\\ 954,\\ in\\ _bootstrap_inner
2022\\-03\\-28\\ 12:26:59,512\\ 344737\\ INFO\\ test\\-server\\ werkzeug:\\ 84\\.192\\.32\\.235\\ \\-\\ \\-\\ \\[28/Mar/2022\\ 12:26:59\\]\\ "POST\\ /longpolling/poll\\ HTTP/1\\.0"\\ 200\\ \\-\\ 8\\ 0\\.003\\ 50\\.009
\\ \\ \\ \\ self\\.run\\(\\)
\\ \\ File\\ "/usr/lib/python3\\.9/threading\\.py",\\ line\\ 892,\\ in\\ run
\\ \\ \\ \\ self\\._target\\(\\*self\\._args,\\ \\*\\*self\\._kwargs\\)
\\ \\ File\\ "/opt/odoo14/odoo/odoo/service/server\\.py",\\ line\\ 432,\\ in\\ target
\\ \\ \\ \\ self\\.cron_thread\\(i\\)
\\ \\ File\\ "/opt/odoo14/odoo/odoo/service/server\\.py",\\ line\\ 408,\\ in\\ cron_thread
\\ \\ \\ \\ for\\ db_name,\\ registry\\ in\\ registries\\.d\\.items\\(\\):
RuntimeError:\\ OrderedDict\\ mutated\\ during\\ iteration

This\\ error\\ happens\\ when\\ the\\ cron\\ job\\ runs\\.

I\\ found\\ this\\ website:\\ https://chowdera.com/2021/09/20210913213439937A.html

Explaining that the problem is related to the python version. Python >=3 has this problem. But oodo14 requests python >=3.6

They suggest a solution, in server.py  in the function

    def cron_thread(self, number):

change the line

for db_name, registry in registries.d.items():
into
for db_name, registry in list(registries.d.items()):
This sounds reasonable, but I wonder why this isn't done by odoo itself?
Could this be the solution? Is this an unreported bug? Or is there something else that is the cause of this?
Thanks for your reply.




2
Avatar
Abbandona
Faris Fathurrahman

my customer bumped into this similar problem, I wonder why, even this post still hasn't got any replies

José Moreno

I've been struggling with this problem myself. It kills the cron jobs after it happens twice (assuming it's because default cron workers is 2). Going to try your solution

Avatar
Reinhard Mengelberg
Risposta migliore

Subject: Solution for RuntimeError: OrderedDict mutated during iteration in Odoo 17 CRON Jobs

I ran into the same issue on Odoo 17 on-premise. The issue lies in the registries.d being modified while being iterated over by the cron_thread method.

Initially, I thought that registries.d would only be modified upon creation, editing, or deleting of a database. However, this is not the case. The registries.d is updated more frequently, for example, when you install a new module on a database.

Upon investigating the /odoo/modules/registry.py file, I found that there are multiple threads or processes accessing and modifying the registry concurrently. 

This concurrent access can lead to the observed behavior, especially if there are background jobs or operations interacting with the registry while CRON jobs are running.

If you run CRON jobs very often, as I do, it is almost inevitable that you will encounter this error at some point. 

The solution suggested by Dries should work. It involves modifying the cron_thread method to iterate over a list copy of registries.d.items(). This prevents the iteration from being disrupted by concurrent modifications.

Here’s the change I’m going to apply:

  1. Locate the cron_thread method in server.py:
    def cron_thread(self, number):
        from odoo.addons.base.models.ir_cron import ir_cron
        conn = odoo.sql_db.db_connect('postgres')
        with conn.cursor() as cr:
            pg_conn = cr._cnx
            cr.execute("SELECT pg_is_in_recovery()")
            in_recovery = cr.fetchone()[0]
            if not in_recovery:
                cr.execute("LISTEN cron_trigger")
            else:
                _logger.warning("PG cluster in recovery mode, cron trigger not activated")
            cr.commit()
    
            while True:
                select.select([pg_conn], [], [], SLEEP_INTERVAL + number)
                time.sleep(number / 100)
                pg_conn.poll()
    
                registries = odoo.modules.registry.Registry.registries
                _logger.debug('cron%d polling for jobs', number)
    
                # Create a copy of the items to avoid mutation during iteration
                for db_name, registry in list(registries.d.items()):
                    if registry.ready:
                        thread = threading.current_thread()
                        thread.start_time = time.time()
                        try:
                            ir_cron._process_jobs(db_name)
                        except Exception:
                            _logger.warning('cron%d encountered an Exception:', number, exc_info=True)
                        finally:
                            thread.start_time = None
    
  2. Restart Odoo:
    sudo systemctl restart odoo
    
  3. Monitor the logs to ensure the error does not reoccur and that CRON jobs are running smoothly:
    sudo tail -f /var/log/odoo/odoo-server.log
    

By making this change, I hope to prevent the OrderedDict mutated during iteration error and ensure that my CRON jobs run without interruption. 

If you encounter similar issues, this approach should help.

Best of luck!


1
Avatar
Abbandona
Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!

Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!

Registrati
Post correlati Risposte Visualizzazioni Attività
Cron job does not execute python code on scheduler, only on Run Manually button. Risolto
cron cronjob
Avatar
Avatar
Avatar
3
set 23
12849
Why does the automated scheduling occasionally stop running?
cronjob v14 Scheduled
Avatar
Avatar
1
ott 25
2969
Using CRON job to download and attach pdf to binary field ODOO16
cron cronjob ODOO16
Avatar
0
ott 24
3092
Cron getting timeout
cron timeout cronjob
Avatar
Avatar
1
ago 24
6142
Possible Bug with Google Maps extension on v14 Risolto
bug v14 googlemaps
Avatar
Avatar
Avatar
Avatar
4
mag 22
5798
Community
  • Tutorial
  • Documentazione
  • Forum
Open source
  • Scarica
  • Github
  • Runbot
  • Traduzioni
Servizi
  • Hosting Odoo.sh
  • Supporto
  • Aggiornamenti
  • Sviluppi personalizzati
  • Formazione
  • Trova un contabile
  • Trova un partner
  • Diventa nostro partner
Chi siamo
  • La nostra azienda
  • Branding
  • Contattaci
  • Lavora con noi
  • Eventi
  • Podcast
  • Blog
  • Clienti
  • Note legali • Privacy
  • Sicurezza
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo è un gestionale di applicazioni aziendali open source pensato per coprire tutte le esigenze della tua azienda: CRM, Vendite, E-commerce, Magazzino, Produzione, Fatturazione elettronica, Project Management e molto altro.

Il punto di forza di Odoo è quello di offrire un ecosistema unico di app facili da usare, intuitive e completamente integrate tra loro.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now