Python Forum
Code that works on py2 and not in py3
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code that works on py2 and not in py3
#1
Hi everyone
this is Pedro and this is my first post. I am trying to write a script to make graphs with xmgrace (graphics program) under linux. There are serveral modules available on the net but none of them work with python 3.
In general terms what I want to do is to launch a process that receives input through a descriptor, in my case the command is 'xmgrace -dpipe <descriptor>'. I wrote the code below that works fine in python 2 but does nothing in python 3.

Any ideas of what's wrong?
Thank you in advance


import os

cmd=('xmgrace','-noask','-dpipe',)

fr,fw=os.pipe()

cmd=cmd+(repr(fr),)

pid=os.fork()

if pid==0:
	for i in range(64):
		if i not in (fr,0,1,2):
			try:
				os.close(i)
			except OSError:
				pass
	os.execvp('xmgrace',cmd)
else:
	os.close(fr)
	pipe=os.fdopen(fw,'w',1)
	
	pipe.write('title "test"\n')
	pipe.flush()
Reply
#2
see: https://docs.python.org/3.8/library/2to3.html
Reply
#3
You could perhaps try os.set_inheritable(fr, True) before the fork.
Reply
#4
(Nov-29-2019, 11:39 AM)Gribouillis Wrote: You could perhaps try os.set_inheritable(fr, True) before the fork.

Thanks a lot, it works now with py2!!

(Nov-29-2019, 11:12 AM)Larz60+ Wrote: see: https://docs.python.org/3.8/library/2to3.html

Thanks a lot
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  My code works on Jupyter Lab/Notebook, but NOT on Visual Code Editor jst 4 879 Nov-15-2023, 06:56 PM
Last Post: jst
  Code works but doesn't give the right results colin_dent 2 674 Jun-22-2023, 06:04 PM
Last Post: jefsummers
  Code used to work 100%, now sometimes works! muzicman0 5 1,384 Jan-13-2023, 05:09 PM
Last Post: muzicman0
  Pyspark - my code works but I want to make it better Kevin 1 1,746 Dec-01-2021, 05:04 AM
Last Post: Kevin
Question email code works in 2.7 but not in 3 micksulley 3 2,538 Nov-04-2021, 09:44 PM
Last Post: micksulley
  My simple code don't works !! Nabi666 1 1,577 Sep-06-2021, 12:10 PM
Last Post: jefsummers
  HackerRank Problem: Code works on VS Code but not on the HackerRank site Pnerd 3 2,594 Feb-28-2021, 07:12 PM
Last Post: Pnerd
Question Google Foobar- Code works in my IDE but not in foobar. Static method? pr3ttykitty 4 4,876 Feb-24-2021, 05:03 PM
Last Post: nilamo
  yet another code that works on 2 but not in 3 rick666 1 1,994 Dec-12-2019, 08:12 PM
Last Post: Gribouillis
  Simple code works in Jupyter but not VS Code Matt_O 2 3,878 Nov-17-2019, 01:15 AM
Last Post: Matt_O

Forum Jump:

User Panel Messages

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