I designed an interface. Think of it as ‘system.py’, the script that contains the main window codes. If the user clicks on the ‘Measurements’ button on the home page, ‘measurementsWin.py’ is run. After making the settings in the ‘Measurements’ window, the user clicks on the ‘Start Measurement’ button and the setup is sent to the devices called ‘Software Defined Radio’. I used the ‘gnuradio’ library to code these devices. I used PySide6 to code the interface. After clicking the ‘Start Measurement’ button, the frequency of the SDRs used in the measurement can be changed according to the settings made by the user (the ‘set_center_freq‘ command is used to achieve this), and this is a very common process. A code is sent to 2 different devices and the frequency of both of them changes. In order to speed up the measurement, I want to send the ‘set_center_freq‘ command to two different devices in parallel. I wanted to do it using Threading, but I saw that even though the program ran, the code did not run in parallel and the duration did not change. I tried to use multiprocessing for this, but the ‘spawn’ method on Windows prevents this and asks me to define multiprocessing in the if __name__ == '__main__' section in the program. However, since changing the frequency is only a small part and is within an interface, it does not seem possible for me to define it in this part (or I could not succeed). When I try it with ‘fork’ on Linux, the program fills the RAM and crashes. Actually, I need to perform this operation on Windows.

I tried to write the codes for changing the frequency in a different script and install them as a module, but an approach such as import frequency_switch does not work because it must be defined in the program if __name__ == '__main__' section. I also tried writing it as a different code file and playing it with a subprocess, but there is a problem here as well, there are codes in the main code file where I define the features of the SDR and I load it to the SDR. Even if I send the variable I keep these to a different script via subprocess, I need to load these features back into the SDR, and this takes a lot of time, and doing this every time leads to a worse scenario than the current situation.

Below I share with you the simple code structure I use to change the frequency.

def switch_source(usrp_source, freq, lo_offset):
    usrp_source.set_center_freq(uhd.tune_request(freq, rf_freq=freq - lo_offset, rf_freq_policy=uhd.tune_request.POLICY_MANUAL), 0)

def switch_sink(usrp_sink, freq, lo_offset):
    usrp_sink.set_center_freq(uhd.tune_request(freq, rf_freq=freq - lo_offset, rf_freq_policy=uhd.tune_request.POLICY_MANUAL), 0)

We load the settings by making the class View() where the SDR’s settings are located and tb = View(), then the measurement is started with tb.start(). After tb.start() the frequency is changed.

def sdrRunView():
    tb = View()

    tb.start()
    measurement_start = True

    while done:
        # doing something.
        switch_source(self.uhd_usrp_source_0, freq, lo_offset)
        switch_sink(self.uhd_usrp_sink_0, freq, lo_offset)
        # doing something.

What can I do to run these 2 functions in parallel?
Or how can I change the entry safe point to run the program?

New contributor

Oğuzhan Gedikli is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.