Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
running two python scripts
#1
Hello,

I am trying to have two python scripts running where one pauses the other. Both scripts do some socket communication (one reads and one writes)

read.py runs continously in the background with a 60 second sleep after each run.
write.py will be run by user interaction/click on a webpage.

These two cannot run at the same time (comm errors). So write.py will need to pause read.py, run, then reactivate write.py.
I am probably looking into this the wrong way. But how would write.py fetch the process of read.py?

Thanks in advance for any tips,
Per
Reply
#2
This sounds like a simple sort of 'Distributed agreement' (in Distributed software design)
I say simple, but the process of managing is not simple.

One way this can be achieved is by inserting a process called a dispatcher into the system. Think of it as a process like
the dispatcher of an emergency center, or a cab company.
The job of the dispatcher is to keep track of all 'courier' processes, and to dispatch, and monitor, time slots,
for each:
Example:
  • Task 1 asks dispatcher for permission to communicate with task3.
  • Dispatcher knows that this task cannot be done concurrently, and that Task 3 is busy.
  • It sends Task 1 a message that says 'Not now'
  • A bit later, task 1 asks for permission again
  • Task 3 is free, so dispatcher gives the OK, but indicates that Task1 must report back when the task is complete.
  • The dispatcher also issues an allotted amount of time in which to finish the task.
  • Once task 1 has been notified, dispatcher starts a timer for that task.
  • if task 1 reports back before that timer times out, dispatcher stops the timer and marks task 3 as being available to other users.
  • If task 1 doesn't report back in the allotted time, the dispatcher will attempt to contact task 3 and ask if busy. If it does not get a response within an allotted time (from the 'are you busy' request), it will assume that something is wrong with task 3 and will reinitialize the task 3 process (make it ready to receive requests, reboot or reset).
  • Task 3 may be able to handle more than one task at a time if so, task 1 may be allowed to go on without notification of completion.
  • and so on.

In order to learn how to do this sort of thing, google for 'Distributed Software Design, Challenges and solutions'
and/or 'distributed agreements'.


For example: http://help.callassoftware.com/m/62791/l...processing
or: https://www.embedded.com/design/prototyp...-Solutions

first one uses commercial software, but has good explanation
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to us python.exe from our network to run scripts cubangt 3 827 Aug-17-2023, 07:53 PM
Last Post: deanhystad
  Running python scripts from github etc pacmyc 7 3,609 Mar-03-2021, 10:26 PM
Last Post: pacmyc
  Running scripts and location of saved interpreted user-defined classes and functions leodavinci1990 3 2,468 Aug-25-2020, 03:43 AM
Last Post: micseydel
  Reading SQL scripts from excel file and run it using python saravanatn 2 2,460 Aug-23-2020, 04:49 PM
Last Post: saravanatn
  No Scripts File present after python installation ag2207 5 4,769 Jul-30-2020, 11:11 AM
Last Post: buran
  Running two scripts and more.... Brian_c 0 1,482 Mar-25-2020, 10:31 PM
Last Post: Brian_c
  How to merge my two python scripts in one ? HK2432 0 2,113 Jan-31-2020, 10:16 PM
Last Post: HK2432
  How can I Open and close .py file from python scripts SayHiii 9 5,625 Dec-17-2019, 06:10 AM
Last Post: Malt
  autostart python scripts in background (Windows10) john36 4 7,576 Oct-01-2019, 01:36 PM
Last Post: john36
  Run macros of excel sheet from python scripts shubhamjainj 3 10,363 May-01-2019, 08:40 AM
Last Post: buran

Forum Jump:

User Panel Messages

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