TypeError: cannot pickle 'socket' object
❓ Questions and Help
Before asking:

search the issues.
search the docs.


What is your question?
when I try to pass a socket.socket parameter to the model, trainer.fit(model) occurred an error:
  File "/disks/disk1/damon/remote_src/YPlatformServer/src/handler.py", line 79, in main
    trainer.fit(model)
  File "/disks/disk1/damon/anaconda3/envs/pytorch/lib/python3.8/site-packages/pytorch_lightning/trainer/states.py", line 48, in wrapped_fn
    result = fn(self, *args, **kwargs)
  File "/disks/disk1/damon/anaconda3/envs/pytorch/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 1064, in fit
    results = self.accelerator_backend.train()
  File "/disks/disk1/damon/anaconda3/envs/pytorch/lib/python3.8/site-packages/pytorch_lightning/accelerators/dp_backend.py", line 97, in train
    results = self.trainer.run_pretrain_routine(model)
  File "/disks/disk1/damon/anaconda3/envs/pytorch/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 1169, in run_pretrain_routine
    self.logger.save()
  File "/disks/disk1/damon/anaconda3/envs/pytorch/lib/python3.8/site-packages/pytorch_lightning/utilities/distributed.py", line 27, in wrapped_fn
    return fn(*args, **kwargs)
  File "/disks/disk1/damon/anaconda3/envs/pytorch/lib/python3.8/site-packages/pytorch_lightning/loggers/tensorboard.py", line 212, in save
    save_hparams_to_yaml(hparams_file, self.hparams)
  File "/disks/disk1/damon/anaconda3/envs/pytorch/lib/python3.8/site-packages/pytorch_lightning/core/saving.py", line 368, in save_hparams_to_yaml
    yaml.dump(hparams, fp)
  File "/disks/disk1/damon/anaconda3/envs/pytorch/lib/python3.8/site-packages/yaml/__init__.py", line 290, in dump
    return dump_all([data], stream, Dumper=Dumper, **kwds)
  File "/disks/disk1/damon/anaconda3/envs/pytorch/lib/python3.8/site-packages/yaml/__init__.py", line 278, in dump_all
    dumper.represent(data)
  File "/disks/disk1/damon/anaconda3/envs/pytorch/lib/python3.8/site-packages/yaml/representer.py", line 27, in represent
    node = self.represent_data(data)
  File "/disks/disk1/damon/anaconda3/envs/pytorch/lib/python3.8/site-packages/yaml/representer.py", line 48, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/disks/disk1/damon/anaconda3/envs/pytorch/lib/python3.8/site-packages/yaml/representer.py", line 207, in represent_dict
    return self.represent_mapping('tag:yaml.org,2002:map', data)
  File "/disks/disk1/damon/anaconda3/envs/pytorch/lib/python3.8/site-packages/yaml/representer.py", line 118, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/disks/disk1/damon/anaconda3/envs/pytorch/lib/python3.8/site-packages/yaml/representer.py", line 52, in represent_data
    node = self.yaml_multi_representers[data_type](self, data)
  File "/disks/disk1/damon/anaconda3/envs/pytorch/lib/python3.8/site-packages/yaml/representer.py", line 317, in represent_object
    reduce = data.__reduce_ex__(2)
  File "/disks/disk1/damon/anaconda3/envs/pytorch/lib/python3.8/socket.py", line 272, in __getstate__
    raise TypeError(f"cannot pickle {self.__class__.__name__!r} object")
TypeError: cannot pickle 'socket' object
Code
    args: dict = update_params(vars(parser_tmp), params)
    args['client']: socket.socket = client
    pl.seed_everything(args['seed'])
    model = p_model(**args)    # it's ok here

    trainer.fit(model)    # occurred an error (described above)
What have you tried?
It seems trainer.fit() will pickle the model, and I know socket cannot be pickled, so I use a global variable. Are there any other methods to solve this problem?
What's your environment?

OS: [e.g. iOS, Linux, Win] Linux
Packaging [e.g. pip, conda] pip
Version [e.g. 0.5.2.1] 0.9.0