Meta tags:
description= Synchronize FrameLocalsProxy accesses with the frame s owning thread: fast locals are accessed under the frame object s critical section, and with the world stopped when the frame may be executing on another thread.
Changes:
Only the fast locals read and write run in the synchronized region. Key lookup (__hash__ / __eq__) runs outside it, so no Python code is executed while the world is stopped.
The extra locals dict is never touched by the running frame, so it does not need stop-the-world. It is fetched under the frame s critical section and used with the dict s own locking.
The value replaced in a cell is decref d after the region, since its destructor can run arbitrary code.
keys(), values(), items() and len() snapshot the fast locals in the region and hold the extra locals dict s critical section while iterating it.
PyFrame_GetVar is synchronized the same way.
Co-authored-by: Sam Gross colesbury@gmail.com
Issue: gh-144446;
Headings (most frequently used words):
uh, oh, navigation, gh, 144446, fix, thread, safety, of, framelocalsproxy, on, executing, frames, 156973, footer, diff, view, menu, repository, there, are, no, files, selected, for, viewing, filter, by, extension,
Text of the page (most frequently used words):
def (51), frame (43), f_locals (40), self (37), for (28), file (25), the (24), and (22), reader (19), runner (18), range (18), github (17), key (17), barrier (16), next (15), this (14), writer (14), 2026 (13), line (12), gen_fn (12), applied (11), while (11), kumaraditya303 (11), that (10), 144446 (10), yield (10), reload (9), diff (9), show (9), hidden (9), characters (9), unicode (9), test (9), extra (9), value (9), proxy (9), code (8), all (8), loading (8), threading_helper (8), wait (8), with (8), assertequal (8), you (7), suggestion (7), cannot (7), suggestions (7), changes (7), thread (7), open (7), close (7), obj (7), 100 (7), gi_frame (7), list (7), import (7), support (7), nov (7), sign (7), comments (6), executing (6), number (6), bidirectional (6), none (6), old (6), get (6), test_frame (6), framelocalsproxy (6), can (5), security (5), please (5), from (5), must (5), there (5), frames (5), another (5), fix (5), safety (5), review (5), learn (5), about (5), view (5), issue (5), expand (5), run_concurrently (5), threading (5), other (5), return (5), class (5), new (5), ref (5), run_with_frame (5), lib (5), commits (5), your (5), pull (4), change (4), deleted (4), add (4), was (4), error (4), page (4), retry (4), build (4), what (4), more (4), rst (4), clear (4), locals (4), values (4), __hash__ (4), generator (4), gen (4), into (4), files (4), python (4), copilot (4), not (3), community (3), navigation (3), request (3), merge (3), batch (3), commit (3), original (3), contains (3), text (3), may (3), interpreted (3), compiled (3), differently (3), than (3), appears (3), below (3), editor (3), reveals (3), desktop (3), delete (3), edit (3), misc (3), news (3), core_and_builtins (3), pq7wxn (3), additions (3), down (3), pass (3), _testcapi (3), 2000 (3), items (3), pop (3), sys (3), locals_dict (3), test_free_threading (3), hide (3), whitespace (3), nbsp (3), filter (3), main (3), cpython (3), 156973 (3), merged (3), account (3), quality (3), tab (3), window (3), refresh (3), session (3), developers (3), changelog (3), customer (3), enterprise (3), grade (3), features (3), contact (2), status (2), privacy (2), terms (2), footer (2), single (2), one (2), viewing (2), closed (2), toggle (2), oops (2), something (2), went (2), wrong (2), free (2), pyframe_getvar (2), deletions (2), reads (2), import_helper (2), keys (2), _getframe (2), are (2), assertraises (2), assertin (2), assertnotin (2), collect (2), __eq__ (2), run (2), world (2), cell (2), make_gen (2), dropper (2), del (2), moves (2), object (2), new_var (2), true (2), writes (2), str (2), iterator (2), hello (2), 264 (2), outer (2), its (2), 162593 (2), 780 (2), selected (2), frameobject (2), objects (2), apply (2), split (2), unified (2), failed (2), load (2), jump (2), extension (2), tests (2), branch (2), remove (2), select (2), tree (2), insights (2), projects (2), actions (2), repository (2), signed (2), universe (2), training (2), integrations (2), stories (2), center (2), documentation (2), business (2), fixes (2), products (2), secret (2), perform, action, time, share, personal, information, manage, cookies, docs, inc, right, now, check, back, later, queued, multi, pending, reviews, has, been, marked, resolved, outdated, existing, order, create, valid, applying, lines, supported, only, per, subset, invalid, because, were, made, annotations, notes, threaded, func, attr, create_frame, race, between, attribute, test_concurrent_frame_clear, nameerror, except, frame_getvar, try, import_module, owner, well, fast, synchronize, test_gen_getvar_while_running, 5000, lambda, iterate, they, modified, test_concurrent_f_locals_extra_iteration, keyerror, valueerror, isinstance, hash, __init__, stopped, test_gen_f_locals_key_runs_python_code, replace, destructor, runs, append, __del__, nonlocal, released, after, restarts, test_gen_setitem_cell_old_value_destructor_stw, dropped, ownership, access, last, reference, test_gen_f_locals_dying_generator, 200, 500, through, synchronized, resuming, test_gen_f_locals_write_suspended, len, reading, test_gen_f_locals_read_while_running, test_concurrent_f_locals_iteration, test_concurrent_f_locals_read_write, test_concurrent_f_locals_write, test_concurrent_f_locals_read_values, 122, 123, 267, module, requires_working_threading, unittest, functools, 263, deletion, behaves, like, mapping, exceptions, testhashmappingprotocol, mapping_tests, framelocalsproxymappingtests, test_setitem_free_var_cleared_frame, assertis, gc_collect, super, weakref, lookup, which, closes, test_setitem_key_closes_generator, conversations, filters, viewed, types, cleare, a934113, a631ae5, https, com, 1444, e94a203, config, a4cae67, some, 5faa4b5, address, minimize, 41630d2, sep, better, d33c175, aug, 44c1536, hold, shift, click, changed, checks, conversation, 559, already, clicking, agree, our, occasionally, send, related, emails, statement, service, maintainers, have, question, project, requests, issues, message, dismiss, alert, switched, accounts, out, appearance, settings, search, pricing, event, talks, workshops, partners, company, forum, events, webinars, blog, resource, connect, resources, premium, advanced, ons, trust, why, evaluate, see, industries, government, manufacturing, financial, services, healthcare, industry, nonprofits, startups, team, enterprises, stage, businesses, source, latest, improvements, across, place, developer, articles, sponsors, trending, repos, explore, customize, certifications, scanning, leak, prevention, protection, vulnerability, detection, remediation, secure, cloud, development, environments, codespaces, analysis, enforcement, automation, ship, coding, agent, tasks, automated, work, hosting, collaboration, platform, menu, skip, content,
|