question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hangs in multiprocessing

See original GitHub issue

This test case hangs in Django 2.0 (works without freeze_time)-

from multiprocessing import Pool

from freezegun import freeze_time
from django.test import TestCase


@freeze_time("2018-02-14 11:00:00")
class MultiProcessingTestCase(TestCase):
    """
    Test case to test if pool process of multiprocessing works
    """
    def test_multi_processing(self):
        print("POOLING")
        with Pool(processes=2) as pool:
            pass
        print("DONE")

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
LionelB5commented, May 9, 2021

I’m seeing similar behaviour after upgrading freezegun from 1.0.0 to 1.1.0.

This code snippet reproduces the issue:

from multiprocessing import Pool
# using Pool from `multiprocessing.dummy` also results in a hang 
# from multiprocessing.dummy import Pool

from freezegun import freeze_time


@freeze_time('2020-01-01 00:00:00')
def reproduce_freezegun_hang():
    pool = Pool()
    pool.close()
    pool.join()  # hangs indefinitely here


if __name__ == '__main__':
    reproduce_freezegun_hang()

If I downgrade freezegun from 1.1.0 to 1.0.0 the hang does not happen. Using the workaround mentioned by boxed in this comment solves the issue. Another workaround is to supply tick=True to freeze_time.

I am using Python 3.9.1.

Contents of requirements.txt:

freezegun==1.1.0
    # via -r requirements.in
python-dateutil==2.8.1
    # via freezegun
six==1.16.0
    # via python-dateutil
0reactions
AaronDMarascocommented, Apr 14, 2022

I got it to stop hanging on join() with extend_ignore_list and adding multiprocessing to that. Sadly, that means that since my UUT is in another process from the test bench, applying the tick() doesn’t affect the copy that got spun off, so looks like I can’t use freezegun for this right now.

I suspect this is also the cause of #359 - unless freezegun implements some kind of multiprocessing manager/namespace to share its state between processes, it’s not gonna work. That’s what my workaround was, but then I had to add the hooks to my class to explicitly call my time synchronization object, which sucks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling Hang in Python Multiprocessing - Sefik Ilkin Serengil
I used apply_async method of multiprocessing.pool module to handle the deadlock problem. I stored the response of the apply_async method in a ...
Read more >
python multiprocessing - process hangs on join for large queue
When I loop over 10,000 or more, my script hangs on worker.join() . It works fine when the loop only goes to 1,000....
Read more >
Why your multiprocessing Pool is stuck (it's full of sharks!)
On Linux, the default configuration of Python's multiprocessing library can lead to deadlocks and brokenness. Learn why, and how to fix it.
Read more >
Code using multiprocessing hangs indefinitely on iPython 8+ if ...
When using pool.map from the multiprocessing library on iPython 8.0.0 and higher, an exception in one of the workers will cause the process ......
Read more >
Program hangs in debug when multiprocessing process starts ...
When starting a multiprocessing process and then that process starts another process, the program will get locked when run in debugger. Following simple...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found