René's URL Explorer Experiment


Title: How to properly hold onto an object in embedded mode? · Issue #267 · clj-python/libpython-clj · GitHub

Open Graph Title: How to properly hold onto an object in embedded mode? · Issue #267 · clj-python/libpython-clj

X Title: How to properly hold onto an object in embedded mode? · Issue #267 · clj-python/libpython-clj

Description: Hello! First, I'd like to thank you for the amazing work on this library. It's a mind-bending level of inter-language interaction, IMO. 👏 I was experimenting with it in the embedded mode. Not sure if I was using it in the intended way, b...

Open Graph Description: Hello! First, I'd like to thank you for the amazing work on this library. It's a mind-bending level of inter-language interaction, IMO. 👏 I was experimenting with it in the embedded mode. Not sure ...

X Description: Hello! First, I'd like to thank you for the amazing work on this library. It's a mind-bending level of inter-language interaction, IMO. 👏 I was experimenting with it in the embedded mode. N...

Opengraph URL: https://github.com/clj-python/libpython-clj/issues/267

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"How to properly hold onto an object in embedded mode?","articleBody":"Hello! First, I'd like to thank you for the amazing work on this library. It's a mind-bending level of inter-language interaction, IMO. 👏\r\n\r\nI was experimenting with it in the embedded mode. Not sure if I was using it in the intended way, but... I took a considerably sized web-app and tried to add some kind of a debugging/introspection interface to it with clj \u0026 cljs.\r\n\r\nThe app uses gevent internally for non-blocking IO operations, so the setup was a bit involving, but in the end it worked out. I'll explain it to get a better picture:\r\n\r\n* app starts as a Python process\r\n* gevent is called at the earliest to do its monkey-patching of IO\r\n* python app continues it's startup\r\n* separate python thread (real OS thread) is started, which does all JVM/clojure initialization (one more thread I guess) and than calls `-main` of the clojure's part of the app\r\n* in the main thread of the python app a queue is created and worker greenlet (fake thread or coroutine) is started to watch it\r\n* when clojure world needs to call something from python world, that involves gevent, it puts a task into a queue for the worker to execute it on the main thread\r\n* if task needs to return something to clojure world, a one-off queue is created to transfer the return value\r\n\r\nIt worked fine, I've even made a little introspection tool, that can peer into a running python app vars and call functions, toggle stuff and so on.\r\n\r\nThen, I've tried to implement a `tap\u003e` like system (just putting python objects into an atom for later inspection), to send info from python to clojure... And was abruptly stopped by a SIGSEGV. :(\r\n\r\n```\r\n#\r\n# A fatal error has been detected by the Java Runtime Environment:\r\n#\r\n#  SIGSEGV (0xb) at pc=0x0000aaaac541ef74, pid=1685, tid=1869\r\n#\r\n# JRE version: OpenJDK Runtime Environment (17.0.12+7) (build 17.0.12+7-Ubuntu-1ubuntu222.04)\r\n# Java VM: OpenJDK 64-Bit Server VM (17.0.12+7-Ubuntu-1ubuntu222.04, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, linux-aarch64)\r\n# Problematic frame:\r\n# C  [python3+0xcef74]\r\n#\r\n# No core dump will be written. Core dumps have been disabled. To enable core dumping, try \"ulimit -c unlimited\" before starting Java again\r\n#\r\n# An error report file with more information is saved as:\r\n# /var/www/hs_err_pid1685.log\r\n#\r\n# If you would like to submit a bug report, please visit:\r\n#   https://bugs.launchpad.net/ubuntu/+source/openjdk-17\r\n# The crash happened outside the Java Virtual Machine in native code.\r\n# See problematic frame for where to report the bug.\r\n#\r\n```\r\n\r\nIt seems that objects I send through \"tap\" got GC'ed on python part. I've tried to find something about holding to objects in the documentation, but nothing was particularly fitting to my case. Digging through the code, I've stumbled upon `track-pyobject` and `incref-and-track`. Using the latter on the objects I send to clojure world did not help though... I still got a SIGSEGV, but in different internal python function. To validate my assumption about objects being GD'ed, I've implemented a dumb \"borrowing\" mechanics on python side (putting objects, to be sent to clojure, in a dict) an it worked okay.\r\n\r\nI'd prefer not to do `-\u003ejvm` on objects, because the idea is to use them again in a python app to replay some actions that it performs.\r\n\r\nMy question: Is there a way to hold onto python objects from clojure in embedded mode so that refcounts will be decreased when references to the pyobjs are GC'ed on the JVM?\r\n\r\nThank you for your time :)\r\n\r\nPython 3.10.12\r\nClojure 1.12\r\nopenjdk 17.0.12 2024-07-16\r\nOpenJDK Runtime Environment (build 17.0.12+7-Ubuntu-1ubuntu222.04)\r\nOpenJDK 64-Bit Server VM (build 17.0.12+7-Ubuntu-1ubuntu222.04, mixed mode, sharing)","author":{"url":"https://github.com/residentsummer","@type":"Person","name":"residentsummer"},"datePublished":"2024-11-10T16:09:30.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":19},"url":"https://github.com/267/libpython-clj/issues/267"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:dbde334d-8649-1689-f821-9c78c0417ee5
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idB152:32101D:233A43E:336F128:6A60CC0E
html-safe-noncee5a50d57d235336f1bf490eb4662073b6e6a445d32e322f2c567fc56adc54822
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMTUyOjMyMTAxRDoyMzNBNDNFOjMzNkYxMjg6NkE2MENDMEUiLCJ2aXNpdG9yX2lkIjoiODk2NzkyNjA5MTYzMzY1MzkwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac77abaccf76e298c4e2f241bbc78750393d337cda4f949a25b8bc24f32193689f
hovercard-subject-tagissue:2647384617
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/clj-python/libpython-clj/267/issue_layout
twitter:imagehttps://opengraph.githubassets.com/b5e0189af3977e0fa73e7767ef22de7d1656ae48ea15daba9e5479c8885b4821/clj-python/libpython-clj/issues/267
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/b5e0189af3977e0fa73e7767ef22de7d1656ae48ea15daba9e5479c8885b4821/clj-python/libpython-clj/issues/267
og:image:altHello! First, I'd like to thank you for the amazing work on this library. It's a mind-bending level of inter-language interaction, IMO. 👏 I was experimenting with it in the embedded mode. Not sure ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameresidentsummer
hostnamegithub.com
expected-hostnamegithub.com
Nonea9556c67fd2e63f5fecafc192915a3b089ef8170a9384ff6b59d7b4a2f6b73f8
turbo-cache-controlno-preview
go-importgithub.com/clj-python/libpython-clj git https://github.com/clj-python/libpython-clj.git
octolytics-dimension-user_id60827878
octolytics-dimension-user_loginclj-python
octolytics-dimension-repository_id187095617
octolytics-dimension-repository_nwoclj-python/libpython-clj
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id187095617
octolytics-dimension-repository_network_root_nwoclj-python/libpython-clj
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasef464e59c3a800187a50f3c89c36ee16df9992c1b
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/clj-python/libpython-clj/issues/267#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fclj-python%2Flibpython-clj%2Fissues%2F267
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
Code QualityEnforce quality at mergehttps://github.com/features/code-quality
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fclj-python%2Flibpython-clj%2Fissues%2F267
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=clj-python%2Flibpython-clj
Reloadhttps://github.com/clj-python/libpython-clj/issues/267
Reloadhttps://github.com/clj-python/libpython-clj/issues/267
Reloadhttps://github.com/clj-python/libpython-clj/issues/267
Please reload this pagehttps://github.com/clj-python/libpython-clj/issues/267
clj-python https://github.com/clj-python
libpython-cljhttps://github.com/clj-python/libpython-clj
Please reload this pagehttps://github.com/clj-python/libpython-clj/issues/267
Notifications https://github.com/login?return_to=%2Fclj-python%2Flibpython-clj
Fork 74 https://github.com/login?return_to=%2Fclj-python%2Flibpython-clj
Star 1.2k https://github.com/login?return_to=%2Fclj-python%2Flibpython-clj
Code https://github.com/clj-python/libpython-clj
Issues 33 https://github.com/clj-python/libpython-clj/issues
Pull requests 4 https://github.com/clj-python/libpython-clj/pulls
Actions https://github.com/clj-python/libpython-clj/actions
Projects https://github.com/clj-python/libpython-clj/projects
Security and quality 0 https://github.com/clj-python/libpython-clj/security
Insights https://github.com/clj-python/libpython-clj/pulse
Code https://github.com/clj-python/libpython-clj
Issues https://github.com/clj-python/libpython-clj/issues
Pull requests https://github.com/clj-python/libpython-clj/pulls
Actions https://github.com/clj-python/libpython-clj/actions
Projects https://github.com/clj-python/libpython-clj/projects
Security and quality https://github.com/clj-python/libpython-clj/security
Insights https://github.com/clj-python/libpython-clj/pulse
How to properly hold onto an object in embedded mode?https://github.com/clj-python/libpython-clj/issues/267#top
https://github.com/residentsummer
residentsummerhttps://github.com/residentsummer
on Nov 10, 2024https://github.com/clj-python/libpython-clj/issues/267#issue-2647384617
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.