Python Forum
Sharing imported modules with Sub Processes?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sharing imported modules with Sub Processes?
#1
Hi all, I am new to Python (and coding as well I guess). I have a menu script which monitors two buttons and calls two different scripts as a sub process depending on the button pressed. The problem is the sub process takes a fair few seconds to load which I think is just all the imports at the start.

I need to speed this up, many of the imported modules in the sub process are loaded by the menu script as well, do I need to import them again in the sub process script?

If so, is there a way of caching / speeding this up?

This is running on an rpi 3 model B using the normal sd card. I have to load the scripts as sub process as I need to time it out after 5 seconds and the sub process script works in a way the traditional timing loops don't work so I have to terminate it instead.

Perhaps I could load some stuff in RAM? Woold that help? No idea how of course :)
Reply
#2
Is it possible to do threads?
Reply
#3
I'm not sure, without looking it up I believe a thread would run simultaneously whereas a sub process pauses? I have used threads in the sub process script already to beep when an incorrect device is scanned on the reader. The danger is that if another button was pressed during the threaded script running (the one invoked by the first button press) that another instance would try to run which would not be good. I suppose there could be some simple logic to check for the presence of either of the two possible threaded scripts and prevent another running.

Also, given that the module running literally pauses the script whilst waiting for a scan on an rfid reader forever there would have to be a way to terminate the thread from the menu script after x seconds as it'll never close otherwise.

Assuming we could resolve my second point then yes threads could be used, would this be quicker?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Best way to secure API key when sharing quarinteen 2 352 Jan-19-2024, 04:46 PM
Last Post: deanhystad
  processes shall be parallel flash77 4 1,125 Sep-20-2022, 11:46 AM
Last Post: DeaD_EyE
  Visual Studio Code Intellisense for Imported Modules Not Working hockinsk 1 2,732 Apr-23-2022, 04:41 PM
Last Post: deanhystad
  Can a module tell where it is being imported from? stevendaprano 3 1,191 Apr-12-2022, 12:46 AM
Last Post: stevendaprano
  How to install modules for 2.7 (or sharing from 3.8)) Persisto 2 2,455 Dec-31-2021, 02:33 PM
Last Post: Persisto
  module detecting if imported vs not Skaperen 1 1,683 Nov-19-2021, 07:43 AM
Last Post: Yoriz
  Killing processes via python Lavina 2 2,633 Aug-04-2021, 06:20 AM
Last Post: warnerarc
  [newbie] Why is a module imported twice? Winfried 3 4,094 Apr-02-2021, 04:48 AM
Last Post: deanhystad
  multiprocessing and sharing object cyrduf 0 2,057 Feb-02-2021, 08:16 PM
Last Post: cyrduf
  How to share a numpy array between 2 processes on Windows? qstdy 0 2,170 Jan-29-2021, 04:24 AM
Last Post: qstdy

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020