@@ -21,6 +21,7 @@ import {
2121 PythonWorkersInternalError ,
2222 PythonUserError ,
2323 simpleRunPython ,
24+ unreachable ,
2425} from 'pyodide-internal:util' ;
2526import { default as MetadataReader } from 'pyodide-internal:runtime-generated/metadata' ;
2627import type { PyodideEntrypointHelper } from 'pyodide:python-entrypoint-helper' ;
@@ -556,6 +557,8 @@ ${describeValue(obj)}
556557 return new PythonUserError ( error ) ;
557558}
558559
560+ type CustomSerialized = { pyodide_entrypoint_helper : true } | { env : true } ;
561+
559562/**
560563 * Create memory snapshot by importing SNAPSHOT_IMPORTS to ensure these packages
561564 * are initialized in the linear memory snapshot and then saving a copy of the
@@ -567,10 +570,13 @@ function makeLinearMemorySnapshot(
567570 pyodide_entrypoint_helper : PyodideEntrypointHelper | null ,
568571 snapshotType : ArtifactBundler . SnapshotType
569572) : Uint8Array {
570- const customHiwireStateSerializer = ( obj : any ) : Record < string , boolean > => {
573+ const customHiwireStateSerializer = ( obj : any ) : CustomSerialized => {
571574 if ( obj === pyodide_entrypoint_helper ) {
572575 return { pyodide_entrypoint_helper : true } ;
573576 }
577+ if ( obj === pyodide_entrypoint_helper ?. cloudflareWorkersModule . env ) {
578+ return { env : true } ;
579+ }
574580 throw createUnserializableObjectError ( obj ) ;
575581 } ;
576582
@@ -843,11 +849,14 @@ export function finalizeBootstrap(
843849 Module : Module ,
844850 pyodide_entrypoint_helper : PyodideEntrypointHelper
845851) : void {
846- const customHiwireStateDeserializer = ( obj : any ) : any => {
852+ const customHiwireStateDeserializer = ( obj : CustomSerialized ) : any => {
847853 if ( 'pyodide_entrypoint_helper' in obj ) {
848854 return pyodide_entrypoint_helper ;
849855 }
850- throw new PythonWorkersInternalError ( `Can't deserialize ${ obj } ` ) ;
856+ if ( 'env' in obj ) {
857+ return pyodide_entrypoint_helper . cloudflareWorkersModule . env ;
858+ }
859+ unreachable ( obj , `Can't deserialize ${ obj } ` ) ;
851860 } ;
852861
853862 Module . API . config . _makeSnapshot =
0 commit comments