403Webshell
Server IP : 121.121.20.254  /  Your IP : 216.73.216.70
Web Server : Microsoft-IIS/10.0
System : Windows NT WEB-SERVER 10.0 build 20348 (Windows Server 2022) AMD64
User : IUSR ( 0)
PHP Version : 8.3.28
Disable Function : NONE
MySQL : ON  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  C:/Python315/Lib/test/test_free_threading/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : C:/Python315/Lib/test/test_free_threading//test_cprofile.py
import unittest

from test.support import threading_helper

import cProfile
import pstats


NTHREADS = 10
INSERT_PER_THREAD = 1000


@threading_helper.requires_working_threading()
class TestCProfile(unittest.TestCase):
    def test_cprofile_racing_list_insert(self):
        def list_insert(lst):
            for i in range(INSERT_PER_THREAD):
                lst.insert(0, i)

        lst = []

        with cProfile.Profile() as pr:
            threading_helper.run_concurrently(
                worker_func=list_insert, nthreads=NTHREADS, args=(lst,)
            )
            pr.create_stats()
            ps = pstats.Stats(pr)
            stats_profile = ps.get_stats_profile()
            list_insert_profile = stats_profile.func_profiles[
                "<method 'insert' of 'list' objects>"
            ]
            # Even though there is no explicit recursive call to insert,
            # cProfile may record some calls as recursive due to limitations
            # in its handling of multithreaded programs. This issue is not
            # directly related to FT Python itself; however, it tends to be
            # more noticeable when using FT Python. Therefore, consider only
            # the calls section and disregard the recursive part.
            list_insert_ncalls = list_insert_profile.ncalls.split("/")[0]
            self.assertEqual(
                int(list_insert_ncalls), NTHREADS * INSERT_PER_THREAD
            )

        self.assertEqual(len(lst), NTHREADS * INSERT_PER_THREAD)

Youez - 2016 - github.com/yon3zu
LinuXploit