#๐Ÿ”’ Problems with a header guard for multiprocessing

11 messages ยท Page 1 of 1 (latest)

mossy pine
#

I have some code with the following structure:

  • import modules
  • header guard:
    • read some files
  • declare functions used by all processes
  • header guard:
    • declare functions used by only main thread
    • create worker processes
    • main algorithm using main processes

The problem is that the 'read some files' section of the code cannot be indented (the file gets read by another program which I don't have control over), meaning I cannot put it inside a header guard. Does anyone have any suggestions on how I can still make this multiprocessing? Any help would be greatly appreciated

wooden spokeBOT
#

@mossy pine

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

mossy pine
#

A goto would work wonders here but python doesn't have anything like that

lapis rampart
mossy pine
#

redefining open might be a little difficult

lapis rampart
#

e.g. to prevent it from reading a file, temporarily redefine open to return an empty StringIO.

mossy pine
#

ok ty, I'll have a try

wooden spokeBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.