Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

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

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

Cron job showing error: RuntimeError: OrderedDict mutated during iteration

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
cronbugcronjobv14
1 Odpowiedz
8466 Widoki
Awatar
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
Awatar
Odrzuć
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

Awatar
Reinhard Mengelberg
Najlepsza odpowiedź

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
Awatar
Odrzuć
Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Powiązane posty Odpowiedzi Widoki Czynność
Cron job does not execute python code on scheduler, only on Run Manually button. Rozwiązane
cron cronjob
Awatar
Awatar
Awatar
3
wrz 23
12848
Why does the automated scheduling occasionally stop running?
cronjob v14 Scheduled
Awatar
Awatar
1
paź 25
2967
Using CRON job to download and attach pdf to binary field ODOO16
cron cronjob ODOO16
Awatar
0
paź 24
3090
Cron getting timeout
cron timeout cronjob
Awatar
Awatar
1
sie 24
6142
Possible Bug with Google Maps extension on v14 Rozwiązane
bug v14 googlemaps
Awatar
Awatar
Awatar
Awatar
4
maj 22
5798
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة 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 to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

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