Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8916337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:13:13+00:00 2026-06-15T05:13:13+00:00

Hi I am using Serial port communication to one of my device using python

  • 0

Hi I am using Serial port communication to one of my device using python codes. It is sending a set of Hex code, Receives a set of data. process it.

This data has to be stored in to a database.

I have another script that has MYSQLdb library pushing it in to the database.

If I do that in sequentially in one script i lose a lot in sampling rate. I can sample up to 32 data sets per second if I dont connect to a database and insert it in to the table.

If I use Multiprocessing and try to run it my sampling rate goes to 0.75, because the parent process is waiting for the child to join. so how can i handle this situation.

Is it possible to run them independently by using a queue to fill data?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:13:14+00:00Added an answer on June 15, 2026 at 5:13 am

    Use threading and Queue.

    here is an example:

    from Queue import Queue
    import threading
    import serial
    
    def readline(ser,output):
        threadLock.acquire()# Get lock to synchronize threads
        output.put(ser.readline())
        threadLock.release()# Free lock to release next thread
        # this will go on forever until you kill the program
    
    if __name__=='__main__':
        output = Queue()
        with serial.Serial(com,baudrate=115200,timeout=1) as ser:
            ser_thread = threading.Thread(target=readline, args=(ser,output,))
            ser_thread.start()
            while(True):
                 threadLock.acquire()#wait until lock is free
                 try:
                     data=output.get()
                 threadLock.release()# Free lock to release next thread
                 # do somthing with data
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading data from a scale using a serial port. Communication is working
I'm using the below code to receive the messages using serial port event handler.
I'm reading data from a serial port using an event listener from the SerialPort
I am using the below code to receive the message via serial port which
I have a problem automagically detecting my Arduino's serial port in Python, using Mac/Linux.
I'm trying to communicate to a device using RS-485 through the serial port. Everything
I am using java comm library for serial port communication in my application. When
I want to send messages through the serial port using PySerial. One of the
I want to write communication interface via serial port. (using Qt) I have QSerialPort
I am using Serial port to receive the messages. The below function is running

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.